From: Corentin Lefrere Date: Tue, 16 Dec 2025 14:42:10 +0000 (+0100) Subject: Adding op_count.c X-Git-Url: https://git.uwuaxy.net/?a=commitdiff_plain;h=076180f3ed645a38a58337170a6d061545df2dc5;p=axy%2Fft%2Fpushswap.git Adding op_count.c --- diff --git a/Makefile b/Makefile index f90e9ea..4de4d74 100644 --- 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 index 0000000..cd2337e --- /dev/null +++ b/op_count.c @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* op_count.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: clefrere +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/pushswap.h b/pushswap.h index 16b06f1..5677b7e 100644 --- a/pushswap.h +++ b/pushswap.h @@ -6,7 +6,7 @@ /* By: clefrere +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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));