]> Untitled Git - axy/ft/pushswap.git/commitdiff
Adding op_count.c
authorCorentin Lefrere <clefrere@k1r1p10.42mulhouse.fr>
Tue, 16 Dec 2025 14:42:10 +0000 (15:42 +0100)
committerCorentin Lefrere <clefrere@k1r1p10.42mulhouse.fr>
Tue, 16 Dec 2025 14:42:10 +0000 (15:42 +0100)
Makefile
op_count.c [new file with mode: 0644]
pushswap.h

index f90e9ea3664963a3d0d151eeea658c7bf050f3e7..4de4d74c47b90c2d14889fff6eb0e9c4db607a7a 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_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_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
 
 RESSRCS=_res_leaf_sort_lookup.h
 
diff --git a/op_count.c b/op_count.c
new file mode 100644 (file)
index 0000000..cd2337e
--- /dev/null
@@ -0,0 +1,43 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   op_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       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "leaf_sort.h"
+
+static void    op_count_inner(size_t *data, t_stacks *stack)
+{
+       (void) stack;
+       data[0]++;
+}
+
+t_closure      op_count(size_t *dst)
+{
+       t_closure       res;
+
+       dst[0] = 0;
+       res.data = dst;
+       res.func = &op_count_inner;
+       return (res);
+}
+
+t_ops  ops_count(t_ops_count *counter)
+{
+       t_ops   res;
+       t_op    op;
+
+       op = OP_SA;
+       while (op <= OP_RRR)
+       {
+               res.ops[op] = op_count(&counter->counters[op]);
+               op++;
+       }
+       return (res);
+}
index 16b06f1cbd5e1abbb718b54d495c80c78a180035..5677b7e0db1de92f9fa44ca0c9e8368c16d0e709 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 14:54:32 by agilliar         ###   ########.fr       */
+/*   Updated: 2025/12/16 15:40:10 by clefrere         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -77,6 +77,11 @@ typedef struct s_ops
        t_closure       ops[11];
 }      t_ops;
 
+typedef struct s__ops_count
+{
+       size_t  counters[11];
+}      t_ops_count;
+
 typedef struct s_list
 {
        size_t  len;
@@ -149,6 +154,9 @@ 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));