everything in src|include should pass the norminette now

This commit is contained in:
Maieul BOYER 2024-02-08 14:27:45 +01:00
parent 3ab3a384c3
commit ed0c78d8a2
No known key found for this signature in database
31 changed files with 453 additions and 384 deletions

View file

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* best_index_to_move.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/08 14:18:43 by maiboyer #+# #+# */
/* Updated: 2024/02/08 14:20:01 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef BEST_INDEX_TO_MOVE_H
# define BEST_INDEX_TO_MOVE_H
# include "app/best_move.h"
# include "app/state.h"
# include "me/types.h"
# include "me/vec/vec_i64.h"
struct s_best_index_to_move
{
t_state *state;
t_vec_i64 *from;
t_vec_i64 *to;
t_iter_pos_func f;
t_usize i;
};
#endif /* BEST_INDEX_TO_MOVE_H */

View file

@ -6,36 +6,38 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/29 20:10:21 by maiboyer #+# #+# */
/* Updated: 2024/02/02 22:48:02 by maiboyer ### ########.fr */
/* Updated: 2024/02/08 13:30:30 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef BEST_MOVE_H
#define BEST_MOVE_H
# define BEST_MOVE_H
#include "app/state.h"
#include "me/vec/vec_i64.h"
# include "app/state.h"
# include "me/vec/vec_i64.h"
struct s_functions
struct s_functions
{
void (*forward)(void *);
void (*reverse)(void *);
void (*forward)(void *);
void (*reverse)(void *);
};
typedef t_usize (*t_iter_pos_func)(t_vec_i64 *);
typedef t_usize (*t_iter_pos_func)(t_vec_i64 *);
typedef struct s_best_move_args
{
t_iter_pos_func iter_func;
t_usize index;
t_vec_i64 *from;
t_vec_i64 *to;
void *args;
struct s_functions main;
struct s_functions other;
struct s_functions both;
} t_best_move_args;
t_iter_pos_func iter_func;
t_usize index;
t_vec_i64 *from;
t_vec_i64 *to;
void *args;
struct s_functions main;
struct s_functions other;
struct s_functions both;
bool print_stuff;
} t_best_move_args;
void run_func_with_best_rotate_for_item(t_state *state, t_best_move_args data);
void run_func_with_best_rotate_for_item(t_state *state,
t_best_move_args data);
#endif /* BEST_MOVE_H */

View file

@ -6,23 +6,23 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/29 21:31:42 by maiboyer #+# #+# */
/* Updated: 2024/02/02 22:47:44 by maiboyer ### ########.fr */
/* Updated: 2024/02/08 14:22:49 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef BEST_MOVE_INNER_H
#define BEST_MOVE_INNER_H
# define BEST_MOVE_INNER_H
#include "app/best_move.h"
#include "app/rotate.h"
#include "app/state.h"
#include "me/types.h"
#include "me/vec/vec_i64.h"
# include "app/best_move.h"
# include "app/rotate.h"
# include "app/state.h"
# include "me/types.h"
# include "me/vec/vec_i64.h"
typedef void (*t_banana_func)(void *);
typedef void (*t_banana_func)(void *);
static inline t_banana_func choose_func(struct s_functions *funcs,
t_rotation rotate)
static inline t_banana_func choose_func(struct s_functions *funcs,
t_rotation rotate)
{
if (rotate.direction == FORWARD)
return (funcs->forward);
@ -31,4 +31,28 @@ static inline t_banana_func choose_func(struct s_functions *funcs,
return (NULL);
}
static inline t_isize abs_diff(t_isize lhs, t_isize rhs)
{
if (lhs > rhs)
return (lhs - rhs);
else
return (rhs - lhs);
}
static inline t_isize min(t_isize lhs, t_isize rhs)
{
if (lhs > rhs)
return (rhs);
else
return (lhs);
}
static inline t_isize max(t_isize lhs, t_isize rhs)
{
if (lhs < rhs)
return (rhs);
else
return (lhs);
}
#endif /* BEST_MOVE_INNER_H */

View file

@ -11,12 +11,12 @@
/* ************************************************************************** */
#ifndef FIND_ITER_H
#define FIND_ITER_H
# define FIND_ITER_H
#include "me/types.h"
#include "me/vec/vec_i64.h"
# include "me/types.h"
# include "me/vec/vec_i64.h"
t_usize min_iter_zero_pos(t_vec_i64 *vec);
t_usize max_iter_zero_pos(t_vec_i64 *vec);
t_usize min_iter_zero_pos(t_vec_i64 *vec);
t_usize max_iter_zero_pos(t_vec_i64 *vec);
#endif /* FIND_ITER_H */

View file

@ -11,19 +11,19 @@
/* ************************************************************************** */
#ifndef FIND_PLACE_H
#define FIND_PLACE_H
# define FIND_PLACE_H
#include "app/state.h"
#include "me/types.h"
# include "app/state.h"
# include "me/types.h"
typedef struct s_find_place_iter_state
{
t_usize current_index;
t_usize found_index;
t_usize current_index;
t_usize found_index;
t_i64 to_find_elem;
} t_find_place_iter_state;
} t_find_place_iter_state;
t_usize find_place(t_i64 elem, t_state *state);
t_usize find_place(t_i64 elem, t_state *state);
#endif /* FIND_PLACE_H */

View file

@ -11,14 +11,14 @@
/* ************************************************************************** */
#ifndef ITER_STATE_H
#define ITER_STATE_H
# define ITER_STATE_H
#include "me/types.h"
# include "me/types.h"
typedef struct s_iter_state
{
t_usize pos;
t_usize pos;
t_i64 elem;
} t_iter_state;
} t_iter_state;
#endif /* ITER_STATE_H */

View file

@ -13,7 +13,6 @@
#ifndef MOVES_H
# define MOVES_H
# include "app/state.h"
# include "app/types/type_move.h"
# include "me/types.h"

View file

@ -6,53 +6,51 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/29 19:00:18 by maiboyer #+# #+# */
/* Updated: 2024/02/02 22:42:31 by maiboyer ### ########.fr */
/* Updated: 2024/02/08 13:33:09 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ROTATE_H
#define ROTATE_H
# define ROTATE_H
#include "me/types.h"
# include "me/types.h"
enum e_rotation_direction
enum e_rotation_direction
{
FORWARD,
REVERSE,
};
typedef struct s_rotation
{
t_usize value;
t_usize ring_size;
enum e_rotation_direction direction;
} t_rotation;
t_isize value;
t_isize ring_size;
enum e_rotation_direction direction;
} t_rotation;
static inline t_rotation forward(t_usize by, t_usize ring_size)
static inline t_rotation forward(t_isize by, t_isize ring_size)
{
return ((t_rotation){
.value = by, .ring_size = ring_size, .direction = FORWARD});
return ((t_rotation){.value = by, .ring_size = ring_size,
.direction = FORWARD});
}
static inline t_rotation reverse(t_usize by, t_usize ring_size)
static inline t_rotation reverse(t_isize by, t_isize ring_size)
{
return ((t_rotation){
.value = by, .ring_size = ring_size, .direction = REVERSE});
return ((t_rotation){.value = by, .ring_size = ring_size,
.direction = REVERSE});
}
static inline t_rotation flip(t_rotation rot)
static inline t_rotation flip(t_rotation rot)
{
enum e_rotation_direction flipped;
enum e_rotation_direction flipped;
if (rot.direction == FORWARD)
flipped = REVERSE;
else if (rot.direction == REVERSE)
flipped = FORWARD;
else
else
return (rot);
return ((t_rotation){.value = rot.ring_size - rot.value,
.ring_size = rot.ring_size,
.direction = flipped});
.ring_size = rot.ring_size, .direction = flipped});
}
#endif /* ROTATE_H */

View file

@ -11,25 +11,25 @@
/* ************************************************************************** */
#ifndef STATE_H
#define STATE_H
# define STATE_H
#include "me/types.h"
#include "me/vec/vec_i64.h"
#include "me/vec/vec_i64_bool.h"
# include "me/types.h"
# include "me/vec/vec_i64.h"
# include "me/vec/vec_i64_bool.h"
typedef struct s_state
{
t_vec_i64_bool sorted;
t_vec_i64 stack_a;
t_vec_i64 stack_b;
} t_state;
t_vec_i64_bool sorted;
t_vec_i64 stack_a;
t_vec_i64 stack_b;
} t_state;
t_state parses_arguments(t_usize count, t_str nums[]);
void free_state(t_state state);
t_state parses_arguments(t_usize count, t_str nums[]);
void free_state(t_state state);
static inline void make_sorted_true_for_elem(t_state *s, t_i64 elem)
static inline void make_sorted_true_for_elem(t_state *s, t_i64 elem)
{
t_usize i;
t_usize i;
i = 0;
while (i < s->sorted.len)
@ -37,15 +37,15 @@ static inline void make_sorted_true_for_elem(t_state *s, t_i64 elem)
if (s->sorted.buffer[i].value == elem)
{
s->sorted.buffer[i].active = true;
return;
return ;
}
i++;
}
}
static inline void make_sorted_true_from_stack(t_state *s, t_vec_i64 *stack)
static inline void make_sorted_true_from_stack(t_state *s, t_vec_i64 *stack)
{
t_usize i;
t_usize i;
i = 0;
while (i < stack->len)
@ -54,9 +54,9 @@ static inline void make_sorted_true_from_stack(t_state *s, t_vec_i64 *stack)
}
}
static inline void make_sorted_all_false(t_state *s)
static inline void make_sorted_all_false(t_state *s)
{
t_usize i;
t_usize i;
i = 0;
while (i < s->sorted.len)

View file

@ -11,11 +11,11 @@
/* ************************************************************************** */
#ifndef TARGET_H
#define TARGET_H
# define TARGET_H
#include "app/rotate.h"
#include "me/types.h"
# include "app/rotate.h"
# include "me/types.h"
t_rotation target(t_usize from, t_usize to, t_usize ring_size);
t_rotation target(t_usize from, t_usize to, t_usize ring_size);
#endif /* TARGET_H */

View file

@ -11,14 +11,14 @@
/* ************************************************************************** */
#ifndef TYPE_I64_BOOL_H
#define TYPE_I64_BOOL_H
# define TYPE_I64_BOOL_H
#include "me/types.h"
# include "me/types.h"
typedef struct s_i64_bool
{
t_i64 value;
bool active;
} t_i64_bool;
t_i64 value;
bool active;
} t_i64_bool;
#endif /* TYPE_I64_BOOL_H */

View file

@ -11,20 +11,20 @@
/* ************************************************************************** */
#ifndef STR_TO_NUMBERS_H
#define STR_TO_NUMBERS_H
# define STR_TO_NUMBERS_H
#include "me/types.h"
# include "me/types.h"
t_error str_to_isize(t_const_str str, t_u32 radix, t_isize *out);
t_error str_to_i64(t_const_str str, t_u32 radix, t_i64 *out);
t_error str_to_i32(t_const_str str, t_u32 radix, t_i32 *out);
t_error str_to_i16(t_const_str str, t_u32 radix, t_i16 *out);
t_error str_to_i8(t_const_str str, t_u32 radix, t_i8 *out);
t_error str_to_isize(t_const_str str, t_u32 radix, t_isize *out);
t_error str_to_i64(t_const_str str, t_u32 radix, t_i64 *out);
t_error str_to_i32(t_const_str str, t_u32 radix, t_i32 *out);
t_error str_to_i16(t_const_str str, t_u32 radix, t_i16 *out);
t_error str_to_i8(t_const_str str, t_u32 radix, t_i8 *out);
t_error str_to_usize(t_const_str str, t_u32 radix, t_usize *out);
t_error str_to_u64(t_const_str str, t_u32 radix, t_u64 *out);
t_error str_to_u32(t_const_str str, t_u32 radix, t_u32 *out);
t_error str_to_u16(t_const_str str, t_u32 radix, t_u16 *out);
t_error str_to_u8(t_const_str str, t_u32 radix, t_u8 *out);
t_error str_to_usize(t_const_str str, t_u32 radix, t_usize *out);
t_error str_to_u64(t_const_str str, t_u32 radix, t_u64 *out);
t_error str_to_u32(t_const_str str, t_u32 radix, t_u32 *out);
t_error str_to_u16(t_const_str str, t_u32 radix, t_u16 *out);
t_error str_to_u8(t_const_str str, t_u32 radix, t_u8 *out);
#endif /* STR_TO_NUMBERS_H */