]> Untitled Git - axy/ft/pushswap.git/commitdiff
Added counters to main
author= <=>
Tue, 16 Dec 2025 18:30:14 +0000 (19:30 +0100)
committer= <=>
Tue, 16 Dec 2025 18:30:14 +0000 (19:30 +0100)
Makefile
main_pushswap.c
op_output.c
ops_count.c [moved from op_count.c with 85% similarity]
ops_stackops.c [moved from ops_groups.c with 72% similarity]
pushswap.h

index 4de4d74c47b90c2d14889fff6eb0e9c4db607a7a..f743838103bb5dd0c66d615f62f28cd9786f4cbd 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 NAME=push_swap
 
-SRCS=algorithm_complex.c algorithm_leafsort.c algorithm_simple.c cheatalloc.c clist.c closure.c leaf_sort.c leaf_sort_index.c leaf_sort_parse.c list.c main_pushswap.c op_count.c op_output.c op_p.c op_parse.c op_r.c op_rr.c op_s.c ops.c ops_groups.c ops_optimizer.c output.c psval.c slice.c splitsort.c splitsort_final.c splitsort_iter.c splitsort_part.c stack.c stacks.c stacks_get.c
+SRCS=algorithm_complex.c algorithm_leafsort.c algorithm_simple.c cheatalloc.c clist.c closure.c leaf_sort.c leaf_sort_index.c leaf_sort_parse.c list.c main_pushswap.c op_output.c op_p.c op_parse.c op_r.c op_rr.c op_s.c ops.c ops_count.c ops_optimizer.c ops_stackops.c output.c psval.c slice.c splitsort.c splitsort_final.c splitsort_iter.c splitsort_part.c stack.c stacks.c stacks_get.c
 
 RESSRCS=_res_leaf_sort_lookup.h
 
index b9c59bdbe76eed9f3ca225008e37657881f33105..a64c52c20e5897ae0ad66927c559a0bf48571783 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: clefrere <clefrere@student.42.fr>          +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/12/02 22:15:12 by agilliar          #+#    #+#             */
-/*   Updated: 2025/12/16 14:55:34 by agilliar         ###   ########.fr       */
+/*   Updated: 2025/12/16 19:13:54 by agilliar         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -40,11 +40,34 @@ static void arg_step(char *str, t_args *arg)
                stack_push_back(&arg->state.a, psval_parse(str));
 }
 
-int    main(int argc, char **argv)
+typedef struct s_benchres
+{
+       t_ops_count     pre_opt;
+       t_ops_count     post_opt;
+       t_slice         strategy;
+       float           disorder;
+}      t_benchres;
+
+static t_benchres      pushswap_solve(t_args *args)
 {
-       t_args          args;
        t_ops           ops;
        t_optimizer     opt;
+       t_benchres      res;
+
+       ops = ops_compose(ops_output(), ops_count(&res.post_opt));
+       ops = ops_optimizer(ops, &opt);
+       ops = ops_compose(ops_stackops(), ops);
+       ops = ops_compose(ops_count(&res.pre_opt), ops);
+       stacks_apply(&args->state, &ops, args->algo);
+       ops_optimizer_commit(&opt, &args->state);
+       return (res);
+}
+
+#include <stdio.h>
+int    main(int argc, char **argv)
+{
+       t_args          args;
+       t_benchres      res;
        int                     i;
 
        args.state = stacks_new();
@@ -53,9 +76,9 @@ int   main(int argc, char **argv)
        i = 1;
        while (i < argc)
                arg_step(argv[i++], &args);
-       ops = ops_compose(ops_stackops(), ops_optimizer(ops_output(), &opt));
-       stacks_apply(&args.state, &ops, args.algo);
-       ops_optimizer_commit(&opt, &args.state);
+       res = pushswap_solve(&args);
        output_flush();
+       printf("pre: %lu\n", res.pre_opt.counters[OP_RR]);
+       printf("post: %lu\n", res.post_opt.counters[OP_RR]);
        cheatexit(!stacks_is_solved(&args.state));
 }
index 30569e407dc8df7a8a7cca3b63d80783ae314d10..5622c8bd3d221bd2b20fd2e6d96ebf0fdd0db000 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: agilliar <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/12/03 12:28:28 by agilliar          #+#    #+#             */
-/*   Updated: 2025/12/16 12:48:13 by agilliar         ###   ########.fr       */
+/*   Updated: 2025/12/16 19:07:40 by agilliar         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -18,7 +18,7 @@ static void   op_output_inner(const char *data, t_stack *stack)
        output_str_ln(data);
 }
 
-t_closure      op_output(t_op op)
+static t_closure       op_output(t_op op)
 {
        t_closure                       res;
        const char *const       ops[11] = {
@@ -39,3 +39,8 @@ t_closure     op_output(t_op op)
        res.func = &op_output_inner;
        return (res);
 }
+
+t_ops  ops_output(void)
+{
+       return (ops_init(op_output));
+}
similarity index 85%
rename from op_count.c
rename to ops_count.c
index cd2337eb4988e72740f2f0b719f075338b9280d3..973a96bdbab9fb1d23fdaecaf92e2df9ce25ad3e 100644 (file)
@@ -1,16 +1,16 @@
 /* ************************************************************************** */
 /*                                                                            */
 /*                                                        :::      ::::::::   */
-/*   op_count.c                                         :+:      :+:    :+:   */
+/*   ops_count.c                                        :+:      :+:    :+:   */
 /*                                                    +:+ +:+         +:+     */
 /*   By: clefrere <clefrere@student.42.fr>          +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/12/16 12:28:05 by clefrere          #+#    #+#             */
-/*   Updated: 2025/12/16 15:40:32 by clefrere         ###   ########.fr       */
+/*   Updated: 2025/12/16 18:10:40 by agilliar         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
-#include "leaf_sort.h"
+#include "pushswap.h"
 
 static void    op_count_inner(size_t *data, t_stacks *stack)
 {
@@ -18,7 +18,7 @@ static void   op_count_inner(size_t *data, t_stacks *stack)
        data[0]++;
 }
 
-t_closure      op_count(size_t *dst)
+static t_closure       op_count(size_t *dst)
 {
        t_closure       res;
 
similarity index 72%
rename from ops_groups.c
rename to ops_stackops.c
index 63b7f06675e9b07a041a8a57d34e6fef48df30ca..589a2fa1961d70deb1c936f42ab4b91d5a0111f3 100644 (file)
@@ -1,17 +1,29 @@
 /* ************************************************************************** */
 /*                                                                            */
 /*                                                        :::      ::::::::   */
-/*   ops_groups.c                                       :+:      :+:    :+:   */
+/*   ops_stackops.c                                     :+:      :+:    :+:   */
 /*                                                    +:+ +:+         +:+     */
 /*   By: agilliar <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/12/08 17:02:23 by agilliar          #+#    #+#             */
-/*   Updated: 2025/12/08 17:56:36 by agilliar         ###   ########.fr       */
+/*   Updated: 2025/12/16 19:08:41 by agilliar         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #include "pushswap.h"
 
+t_closure      op_pa(void);
+t_closure      op_pb(void);
+t_closure      op_ra(void);
+t_closure      op_rb(void);
+t_closure      op_rr(void);
+t_closure      op_rra(void);
+t_closure      op_rrb(void);
+t_closure      op_rrr(void);
+t_closure      op_sa(void);
+t_closure      op_sb(void);
+t_closure      op_ss(void);
+
 t_ops  ops_stackops(void)
 {
        const t_ops     ops = {
@@ -32,8 +44,3 @@ t_ops ops_stackops(void)
 
        return (ops);
 }
-
-t_ops  ops_output(void)
-{
-       return (ops_init(op_output));
-}
index 5677b7e0db1de92f9fa44ca0c9e8368c16d0e709..e9a077aaf394ddc92a1b0b450a86e9e608b3c2aa 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: clefrere <clefrere@student.42.fr>          +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/12/02 11:02:44 by agilliar          #+#    #+#             */
-/*   Updated: 2025/12/16 15:40:10 by clefrere         ###   ########.fr       */
+/*   Updated: 2025/12/16 19:08:25 by agilliar         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -77,7 +77,7 @@ typedef struct s_ops
        t_closure       ops[11];
 }      t_ops;
 
-typedef struct s__ops_count
+typedef struct s_ops_count
 {
        size_t  counters[11];
 }      t_ops_count;
@@ -140,23 +140,6 @@ const t_stack      *stacks_getb(const t_stacks *stacks, bool mirrored);
 
 t_op                   op_parse(t_slice s);
 
-t_closure              op_pa(void);
-t_closure              op_pb(void);
-t_closure              op_ra(void);
-t_closure              op_rb(void);
-t_closure              op_rr(void);
-t_closure              op_rra(void);
-t_closure              op_rrb(void);
-t_closure              op_rrr(void);
-t_closure              op_sa(void);
-t_closure              op_sb(void);
-t_closure              op_ss(void);
-
-t_closure              op_output(t_op op);
-
-t_closure              op_count(size_t *dst);
-t_ops                  ops_count(t_ops_count *counter);
-
 t_closure              op_compose(t_closure first, t_closure second);
 t_ops                  ops_compose(t_ops lhs, t_ops rhs);
 t_ops                  ops_init(t_closure (*gen)(t_op));
@@ -164,6 +147,8 @@ t_ops                       ops_init(t_closure (*gen)(t_op));
 t_ops                  ops_stackops(void);
 t_ops                  ops_output(void);
 
+t_ops                  ops_count(t_ops_count *counter);
+
 t_ops                  ops_optimizer(t_ops commit, t_optimizer *data);
 void                   ops_optimizer_commit(t_optimizer *data, t_stacks *stacks);