push_swap/include/app/state.h
2024-01-31 16:15:47 +01:00

69 lines
1.8 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* state.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 14:27:25 by maiboyer #+# #+# */
/* Updated: 2024/01/31 15:09:44 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STATE_H
#define STATE_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_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)
{
t_usize i;
i = 0;
while (i < s->sorted.len)
{
if (s->sorted.buffer[i].value == elem)
{
s->sorted.buffer[i].active = true;
return;
}
i++;
}
}
static inline void make_sorted_true_from_stack(t_state *s, t_vec_i64 *stack)
{
t_usize i;
i = 0;
while (i < stack->len)
{
make_sorted_true_for_elem(s, stack->buffer[i++]);
}
}
static inline void make_sorted_all_false(t_state *s)
{
t_usize i;
i = 0;
while (i < s->sorted.len)
{
s->sorted.buffer[i].active = false;
i++;
}
}
#endif /* STATE_H */