regenerated stuff

This commit is contained in:
maix0 2024-09-26 18:31:56 +02:00
parent c284eb3786
commit 2e811bcec2
61 changed files with 1022 additions and 1697 deletions

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ast.c :+: :+: :+: */
/* vec_ast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/05 18:46:28 by maiboyer #+# #+# */
/* Updated: 2024/09/19 15:30:00 by rparodi ### ########.fr */
/* Updated: 2023/12/09 17:54:11 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,9 +15,10 @@
#include "me/vec/vec_ast.h"
#include <stdlib.h>
t_vec_ast vec_ast_new(t_usize capacity, t_free_ast_item free_function)
t_vec_ast vec_ast_new(t_usize capacity,
t_free_ast_item free_function)
{
t_vec_ast out;
t_vec_ast out;
out = (t_vec_ast){0};
out.free_func = free_function;
@ -27,8 +28,8 @@ t_vec_ast vec_ast_new(t_usize capacity, t_free_ast_item free_function)
return (out);
}
/// @return true in case of an error
t_error vec_ast_push(t_vec_ast *vec, t_ast_node element)
/// Return true in case of an error
t_error vec_ast_push(t_vec_ast *vec, t_ast_node element)
{
if (vec == NULL)
return (ERROR);
@ -39,9 +40,9 @@ t_error vec_ast_push(t_vec_ast *vec, t_ast_node element)
}
/// Return true in case of an error
t_error vec_ast_reserve(t_vec_ast *vec, t_usize wanted_capacity)
t_error vec_ast_reserve(t_vec_ast *vec, t_usize wanted_capacity)
{
size_t new_capacity;
size_t new_capacity;
if (vec == NULL)
return (ERROR);
@ -50,8 +51,8 @@ t_error vec_ast_reserve(t_vec_ast *vec, t_usize wanted_capacity)
new_capacity = (vec->capacity * 3) / 2 + 1;
while (wanted_capacity > new_capacity)
new_capacity = (new_capacity * 3) / 2 + 1;
vec->buffer = mem_realloc_array(\
vec->buffer, new_capacity, sizeof(t_ast_node));
vec->buffer =
mem_realloc_array(vec->buffer, new_capacity, sizeof(t_ast_node));
vec->capacity = new_capacity;
}
return (NO_ERROR);
@ -59,10 +60,10 @@ t_error vec_ast_reserve(t_vec_ast *vec, t_usize wanted_capacity)
/// Return true if the vector is empty
/// This function is safe to call with value being NULL
t_error vec_ast_pop(t_vec_ast *vec, t_ast_node *value)
t_error vec_ast_pop(t_vec_ast *vec, t_ast_node *value)
{
t_ast_node temp_value;
t_ast_node *ptr;
t_ast_node temp_value;
t_ast_node *ptr;
if (vec == NULL || vec->len == 0)
return (ERROR);
@ -76,10 +77,10 @@ t_error vec_ast_pop(t_vec_ast *vec, t_ast_node *value)
}
/// This function is safe to call with `free_elem` being NULL
void vec_ast_free(t_vec_ast vec)
void vec_ast_free(t_vec_ast vec)
{
if (vec.buffer == NULL)
return ;
return;
if (vec.free_func)
{
while (vec.len)

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ast_functions2.c :+: :+: :+: */
/* vec_ast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 17:59:28 by maiboyer #+# #+# */
/* Updated: 2024/09/19 15:32:36 by rparodi ### ########.fr */
/* Updated: 2023/12/30 17:59:28 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,10 +17,10 @@
#include "me/vec/vec_ast.h"
#include <stdlib.h>
t_error vec_ast_find(t_vec_ast *vec, bool (*fn)(\
const t_ast_node *), t_usize *index)
t_error vec_ast_find(t_vec_ast *vec,
bool (*fn)(const t_ast_node *), t_usize *index)
{
t_usize idx;
t_usize idx;
if (vec == NULL || fn == NULL || index == NULL)
return (ERROR);
@ -37,10 +37,11 @@ t_error vec_ast_find(t_vec_ast *vec, bool (*fn)(\
return (ERROR);
}
t_error vec_ast_find_starting(t_vec_ast *vec, bool (*fn)(\
const t_ast_node *), t_usize starting_index, t_usize *index)
t_error vec_ast_find_starting(t_vec_ast *vec,
bool (*fn)(const t_ast_node *),
t_usize starting_index, t_usize *index)
{
t_usize idx;
t_usize idx;
if (vec == NULL || fn == NULL || index == NULL)
return (ERROR);
@ -57,10 +58,10 @@ t_error vec_ast_find_starting(t_vec_ast *vec, bool (*fn)(\
return (ERROR);
}
t_error vec_ast_all(t_vec_ast *vec, bool (*fn)(\
const t_ast_node *), bool *result)
t_error vec_ast_all(t_vec_ast *vec,
bool (*fn)(const t_ast_node *), bool *result)
{
t_usize idx;
t_usize idx;
if (vec == NULL || fn == NULL || result == NULL)
return (ERROR);
@ -75,10 +76,10 @@ t_error vec_ast_all(t_vec_ast *vec, bool (*fn)(\
return (ERROR);
}
t_error vec_ast_any(t_vec_ast *vec, bool (*fn)(\
const t_ast_node *), bool *result)
t_error vec_ast_any(t_vec_ast *vec,
bool (*fn)(const t_ast_node *), bool *result)
{
t_usize idx;
t_usize idx;
if (vec == NULL || fn == NULL || result == NULL)
return (ERROR);
@ -93,13 +94,15 @@ t_error vec_ast_any(t_vec_ast *vec, bool (*fn)(\
return (ERROR);
}
void vec_ast_iter(t_vec_ast *vec, void (*fn)(\
t_usize index, t_ast_node *value, void *state), void *state)
void vec_ast_iter(t_vec_ast *vec,
void (*fn)(t_usize index, t_ast_node *value,
void *state),
void *state)
{
t_usize idx;
t_usize idx;
if (vec == NULL || fn == NULL)
return ;
return;
idx = 0;
while (idx < vec->len)
{

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ast_functions3.c :+: :+: :+: */
/* vec_ast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 17:59:28 by maiboyer #+# #+# */
/* Updated: 2024/09/19 15:34:10 by rparodi ### ########.fr */
/* Updated: 2023/12/30 17:59:28 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,14 +15,15 @@
#include "me/vec/vec_ast.h"
#include <stdlib.h>
t_error vec_ast_push_front(t_vec_ast *vec, t_ast_node element)
t_error vec_ast_push_front(t_vec_ast *vec,
t_ast_node element)
{
t_usize i;
t_usize i;
if (vec->len == 0)
return (vec_ast_push(vec, element));
i = vec->len - 1;
if (vec->capacity < vec->len + 1 && \
if (vec->capacity < vec->len + 1 &&
vec_ast_reserve(vec, 3 * vec->len / 2 + 1))
return (ERROR);
while (i > 0)
@ -36,9 +37,9 @@ t_error vec_ast_push_front(t_vec_ast *vec, t_ast_node element)
return (NO_ERROR);
}
t_error vec_ast_pop_front(t_vec_ast *vec, t_ast_node *value)
t_error vec_ast_pop_front(t_vec_ast *vec, t_ast_node *value)
{
t_usize i;
t_usize i;
if (vec->len <= 1)
return (vec_ast_pop(vec, value));
@ -54,10 +55,10 @@ t_error vec_ast_pop_front(t_vec_ast *vec, t_ast_node *value)
return (NO_ERROR);
}
void vec_ast_reverse(t_vec_ast *vec)
void vec_ast_reverse(t_vec_ast *vec)
{
t_ast_node temporary;
t_usize i;
t_ast_node temporary;
t_usize i;
i = 0;
while (i < vec->len / 2)
@ -69,9 +70,9 @@ void vec_ast_reverse(t_vec_ast *vec)
}
}
t_error vec_ast_back(t_vec_ast *vec, t_ast_node **out)
t_error vec_ast_back(t_vec_ast *vec, t_ast_node **out)
{
t_ast_node *temporary;
t_ast_node *temporary;
if (out == NULL)
out = &temporary;

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ast_functions4.c :+: :+: :+: */
/* vec_ast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 17:59:28 by maiboyer #+# #+# */
/* Updated: 2024/09/19 15:36:47 by rparodi ### ########.fr */
/* Updated: 2023/12/30 17:59:28 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,7 +15,7 @@
#include "me/vec/vec_ast.h"
#include <stdlib.h>
t_ast_node *vec_ast_get(t_vec_ast *vec, t_usize i)
t_ast_node *vec_ast_get(t_vec_ast *vec, t_usize i)
{
if (vec == NULL || vec->buffer == NULL)
return (NULL);
@ -24,14 +24,14 @@ t_ast_node *vec_ast_get(t_vec_ast *vec, t_usize i)
return (NULL);
}
t_ast_node *vec_ast_last(t_vec_ast *vec)
t_ast_node *vec_ast_last(t_vec_ast *vec)
{
if (vec == NULL || vec->len == 0)
return (NULL);
return (&vec->buffer[vec->len - 1]);
}
void vec_ast_copy_into(t_vec_ast *vec, t_vec_ast *dest)
void vec_ast_copy_into(t_vec_ast *vec, t_vec_ast *dest)
{
if (vec == NULL || dest == NULL)
return ;
@ -39,20 +39,21 @@ void vec_ast_copy_into(t_vec_ast *vec, t_vec_ast *dest)
mem_copy(dest->buffer, vec->buffer, vec->len * sizeof(t_ast_node));
}
struct s_vec_ast_splice_arguments vec_ast_splice_args(
struct s_vec_ast_splice_arguments vec_ast_splice_args(
t_usize index, t_usize old_count, t_usize new_count,
const t_ast_node *elements)
{
return ((struct s_vec_ast_splice_arguments){index, old_count, \
new_count, elements});
return ((struct s_vec_ast_splice_arguments){index, old_count,
new_count, elements});
}
void vec_ast_splice(t_vec_ast *self, struct s_vec_ast_splice_arguments args)
void vec_ast_splice(t_vec_ast *self,
struct s_vec_ast_splice_arguments args)
{
t_ast_node *contents;
t_u32 new_size;
t_u32 old_end;
t_u32 new_end;
t_ast_node *contents;
t_u32 new_size;
t_u32 old_end;
t_u32 new_end;
new_size = self->len + args.new_count - args.old_count;
old_end = args.index + args.old_count;
@ -60,17 +61,17 @@ void vec_ast_splice(t_vec_ast *self, struct s_vec_ast_splice_arguments args)
vec_ast_reserve(self, new_size);
contents = self->buffer;
if (self->len > old_end)
mem_move(contents + new_end, \
contents + old_end, \
(self->len - old_end) * sizeof(t_ast_node));
mem_move(contents + new_end,
contents + old_end,
(self->len - old_end) * sizeof(t_ast_node));
if (args.new_count > 0)
{
if (args.elements)
mem_copy((contents + args.index * sizeof(t_ast_node)), \
args.elements, args.new_count * sizeof(t_ast_node));
mem_copy((contents + args.index * sizeof(t_ast_node)),
args.elements, args.new_count * sizeof(t_ast_node));
else
mem_set_zero((contents + args.index * sizeof(t_ast_node)),
args.new_count * sizeof(t_ast_node));
args.new_count * sizeof(t_ast_node));
}
self->len += args.new_count - args.old_count;
}

View file

@ -1,26 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ast_sort.c :+: :+: :+: */
/* best_move.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/29 20:04:33 by maiboyer #+# #+# */
/* Updated: 2024/09/19 15:37:59 by rparodi ### ########.fr */
/* Updated: 2024/01/31 14:25:00 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/types.h"
#include "me/vec/vec_ast.h"
void vec_ast_sort(t_vec_ast *v, t_vec_ast_sort_fn is_sorted_fn)
void vec_ast_sort(t_vec_ast *v,
t_vec_ast_sort_fn is_sorted_fn)
{
t_usize sorted_part;
t_usize i;
t_ast_node tmp;
t_usize sorted_part;
t_usize i;
t_ast_node tmp;
if (v == NULL)
return ;
return;
sorted_part = v->len;
while (sorted_part > 0)
{