style: noming ast.c
This commit is contained in:
parent
7243dd263d
commit
b8cc83a5c0
1 changed files with 15 additions and 16 deletions
|
|
@ -1,12 +1,12 @@
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* vec_ast.c :+: :+: :+: */
|
/* ast.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/12/05 18:46:28 by maiboyer #+# #+# */
|
/* Created: 2023/12/05 18:46:28 by maiboyer #+# #+# */
|
||||||
/* Updated: 2023/12/09 17:54:11 by maiboyer ### ########.fr */
|
/* Updated: 2024/09/19 15:30:00 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,10 +15,9 @@
|
||||||
#include "me/vec/vec_ast.h"
|
#include "me/vec/vec_ast.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
t_vec_ast vec_ast_new(t_usize capacity,
|
t_vec_ast vec_ast_new(t_usize capacity, t_free_ast_item free_function)
|
||||||
t_free_ast_item free_function)
|
|
||||||
{
|
{
|
||||||
t_vec_ast out;
|
t_vec_ast out;
|
||||||
|
|
||||||
out = (t_vec_ast){0};
|
out = (t_vec_ast){0};
|
||||||
out.free_func = free_function;
|
out.free_func = free_function;
|
||||||
|
|
@ -28,8 +27,8 @@ t_vec_ast vec_ast_new(t_usize capacity,
|
||||||
return (out);
|
return (out);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return true in case of an error
|
/// @return true in case of an error
|
||||||
t_error vec_ast_push(t_vec_ast *vec, t_ast_node element)
|
t_error vec_ast_push(t_vec_ast *vec, t_ast_node element)
|
||||||
{
|
{
|
||||||
if (vec == NULL)
|
if (vec == NULL)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
|
|
@ -40,9 +39,9 @@ t_error vec_ast_push(t_vec_ast *vec, t_ast_node element)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return true in case of an error
|
/// 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)
|
if (vec == NULL)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
|
|
@ -51,8 +50,8 @@ t_error vec_ast_reserve(t_vec_ast *vec, t_usize wanted_capacity)
|
||||||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||||
while (wanted_capacity > new_capacity)
|
while (wanted_capacity > new_capacity)
|
||||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||||
vec->buffer =
|
vec->buffer = mem_realloc_array(\
|
||||||
mem_realloc_array(vec->buffer, new_capacity, sizeof(t_ast_node));
|
vec->buffer, new_capacity, sizeof(t_ast_node));
|
||||||
vec->capacity = new_capacity;
|
vec->capacity = new_capacity;
|
||||||
}
|
}
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
|
|
@ -60,10 +59,10 @@ t_error vec_ast_reserve(t_vec_ast *vec, t_usize wanted_capacity)
|
||||||
|
|
||||||
/// Return true if the vector is empty
|
/// Return true if the vector is empty
|
||||||
/// This function is safe to call with value being NULL
|
/// 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 temp_value;
|
||||||
t_ast_node *ptr;
|
t_ast_node *ptr;
|
||||||
|
|
||||||
if (vec == NULL || vec->len == 0)
|
if (vec == NULL || vec->len == 0)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
|
|
@ -77,10 +76,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
|
/// 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)
|
if (vec.buffer == NULL)
|
||||||
return;
|
return ;
|
||||||
if (vec.free_func)
|
if (vec.free_func)
|
||||||
{
|
{
|
||||||
while (vec.len)
|
while (vec.len)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue