update: normed the rest output

This commit is contained in:
maix0 2024-09-19 17:52:19 +02:00
parent 4a6ea68d08
commit bec1320c5f
26 changed files with 332 additions and 382 deletions

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vec_reduce_action.c :+: :+: :+: */
/* reduce_action.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/05 18:46:28 by maiboyer #+# #+# */
/* Updated: 2023/12/09 17:54:11 by maiboyer ### ########.fr */
/* Updated: 2024/09/19 17:50:33 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,21 +15,22 @@
#include "me/vec/vec_reduce_action.h"
#include <stdlib.h>
t_vec_reduce_action vec_reduce_action_new(t_usize capacity,
t_free_reduce_action_item free_function)
t_vec_reduce_action vec_reduce_action_new(t_usize capacity,
t_free_reduce_action_item free_function)
{
t_vec_reduce_action out;
t_vec_reduce_action out;
out = (t_vec_reduce_action){0};
out.free_func = free_function;
out.buffer = mem_alloc_array(capacity, sizeof(t_reduce_action));
out.buffer = mem_alloc_array(capacity, sizeof(*out.buffer));
if (out.buffer)
out.capacity = capacity;
return (out);
}
/// Return true in case of an error
t_error vec_reduce_action_push(t_vec_reduce_action *vec, t_reduce_action element)
t_error vec_reduce_action_push(t_vec_reduce_action *vec,
t_reduce_action element)
{
if (vec == NULL)
return (ERROR);
@ -40,9 +41,10 @@ t_error vec_reduce_action_push(t_vec_reduce_action *vec, t_reduce_action element
}
/// Return true in case of an error
t_error vec_reduce_action_reserve(t_vec_reduce_action *vec, t_usize wanted_capacity)
t_error vec_reduce_action_reserve(t_vec_reduce_action *vec,
t_usize wanted_capacity)
{
size_t new_capacity;
size_t new_capacity;
if (vec == NULL)
return (ERROR);
@ -51,8 +53,8 @@ t_error vec_reduce_action_reserve(t_vec_reduce_action *vec, t_usize wanted_capac
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_reduce_action));
vec->buffer = mem_realloc_array(vec->buffer, new_capacity,
sizeof(t_reduce_action));
vec->capacity = new_capacity;
}
return (NO_ERROR);
@ -60,10 +62,10 @@ t_error vec_reduce_action_reserve(t_vec_reduce_action *vec, t_usize wanted_capac
/// Return true if the vector is empty
/// This function is safe to call with value being NULL
t_error vec_reduce_action_pop(t_vec_reduce_action *vec, t_reduce_action *value)
t_error vec_reduce_action_pop(t_vec_reduce_action *vec, t_reduce_action *value)
{
t_reduce_action temp_value;
t_reduce_action *ptr;
t_reduce_action temp_value;
t_reduce_action *ptr;
if (vec == NULL || vec->len == 0)
return (ERROR);
@ -77,10 +79,10 @@ t_error vec_reduce_action_pop(t_vec_reduce_action *vec, t_reduce_action *value)
}
/// This function is safe to call with `free_elem` being NULL
void vec_reduce_action_free(t_vec_reduce_action vec)
void vec_reduce_action_free(t_vec_reduce_action vec)
{
if (vec.buffer == NULL)
return;
return ;
if (vec.free_func)
{
while (vec.len)