stdme is fully normed !
This commit is contained in:
parent
2c9a3ee834
commit
4e72b48b4a
21 changed files with 281 additions and 278 deletions
|
|
@ -1,12 +1,12 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* vec_buf_str.c :+: :+: :+: */
|
||||
/* buf_str.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/08/01 07:31:27 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,10 +15,10 @@
|
|||
#include "me/vec/vec_buf_str.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_vec_buf_str vec_buf_str_new(t_usize capacity,
|
||||
t_free_buf_str_item free_function)
|
||||
t_vec_buf_str vec_buf_str_new(t_usize capacity,
|
||||
t_free_buf_str_item free_function)
|
||||
{
|
||||
t_vec_buf_str out;
|
||||
t_vec_buf_str out;
|
||||
|
||||
out = (t_vec_buf_str){0};
|
||||
out.free_func = free_function;
|
||||
|
|
@ -29,7 +29,7 @@ t_vec_buf_str vec_buf_str_new(t_usize capacity,
|
|||
}
|
||||
|
||||
/// Return true in case of an error
|
||||
t_error vec_buf_str_push(t_vec_buf_str *vec, t_string element)
|
||||
t_error vec_buf_str_push(t_vec_buf_str *vec, t_string element)
|
||||
{
|
||||
if (vec == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -40,9 +40,9 @@ t_error vec_buf_str_push(t_vec_buf_str *vec, t_string element)
|
|||
}
|
||||
|
||||
/// Return true in case of an error
|
||||
t_error vec_buf_str_reserve(t_vec_buf_str *vec, t_usize wanted_capacity)
|
||||
t_error vec_buf_str_reserve(t_vec_buf_str *vec, t_usize wanted_capacity)
|
||||
{
|
||||
size_t new_capacity;
|
||||
size_t new_capacity;
|
||||
|
||||
if (vec == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -51,8 +51,8 @@ t_error vec_buf_str_reserve(t_vec_buf_str *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_string));
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, \
|
||||
sizeof(t_string));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
return (NO_ERROR);
|
||||
|
|
@ -60,10 +60,10 @@ t_error vec_buf_str_reserve(t_vec_buf_str *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_buf_str_pop(t_vec_buf_str *vec, t_string *value)
|
||||
t_error vec_buf_str_pop(t_vec_buf_str *vec, t_string *value)
|
||||
{
|
||||
t_string temp_value;
|
||||
t_string *ptr;
|
||||
t_string temp_value;
|
||||
t_string *ptr;
|
||||
|
||||
if (vec == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -79,10 +79,10 @@ t_error vec_buf_str_pop(t_vec_buf_str *vec, t_string *value)
|
|||
}
|
||||
|
||||
/// This function is safe to call with `free_elem` being NULL
|
||||
void vec_buf_str_free(t_vec_buf_str vec)
|
||||
void vec_buf_str_free(t_vec_buf_str vec)
|
||||
{
|
||||
if (vec.buffer == NULL)
|
||||
return;
|
||||
return ;
|
||||
if (vec.free_func)
|
||||
{
|
||||
while (vec.len)
|
||||
|
|
|
|||
|
|
@ -10,17 +10,15 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_buf_str.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_error vec_buf_str_find(t_vec_buf_str *vec,
|
||||
bool (*fn)(const t_string *), t_usize *index)
|
||||
t_error vec_buf_str_find(t_vec_buf_str *vec, bool (*fn)(const t_string *),
|
||||
t_usize *index)
|
||||
{
|
||||
t_usize idx;
|
||||
t_usize idx;
|
||||
|
||||
if (vec == NULL || fn == NULL || index == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -37,11 +35,10 @@ t_error vec_buf_str_find(t_vec_buf_str *vec,
|
|||
return (ERROR);
|
||||
}
|
||||
|
||||
t_error vec_buf_str_find_starting(t_vec_buf_str *vec,
|
||||
bool (*fn)(const t_string *),
|
||||
t_usize starting_index, t_usize *index)
|
||||
t_error vec_buf_str_find_starting(t_vec_buf_str *vec,
|
||||
bool (*fn)(const t_string *), t_usize starting_index, t_usize *index)
|
||||
{
|
||||
t_usize idx;
|
||||
t_usize idx;
|
||||
|
||||
if (vec == NULL || fn == NULL || index == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -58,10 +55,10 @@ t_error vec_buf_str_find_starting(t_vec_buf_str *vec,
|
|||
return (ERROR);
|
||||
}
|
||||
|
||||
t_error vec_buf_str_all(t_vec_buf_str *vec,
|
||||
bool (*fn)(const t_string *), bool *result)
|
||||
t_error vec_buf_str_all(t_vec_buf_str *vec, bool (*fn)(const t_string *),
|
||||
bool *result)
|
||||
{
|
||||
t_usize idx;
|
||||
t_usize idx;
|
||||
|
||||
if (vec == NULL || fn == NULL || result == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -76,10 +73,10 @@ t_error vec_buf_str_all(t_vec_buf_str *vec,
|
|||
return (ERROR);
|
||||
}
|
||||
|
||||
t_error vec_buf_str_any(t_vec_buf_str *vec,
|
||||
bool (*fn)(const t_string *), bool *result)
|
||||
t_error vec_buf_str_any(t_vec_buf_str *vec, bool (*fn)(const t_string *),
|
||||
bool *result)
|
||||
{
|
||||
t_usize idx;
|
||||
t_usize idx;
|
||||
|
||||
if (vec == NULL || fn == NULL || result == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -94,15 +91,13 @@ t_error vec_buf_str_any(t_vec_buf_str *vec,
|
|||
return (ERROR);
|
||||
}
|
||||
|
||||
void vec_buf_str_iter(t_vec_buf_str *vec,
|
||||
void (*fn)(t_usize index, t_string *value,
|
||||
void *state),
|
||||
void *state)
|
||||
void vec_buf_str_iter(t_vec_buf_str *vec, void (*fn)(t_usize index,
|
||||
t_string *value, void *state), void *state)
|
||||
{
|
||||
t_usize idx;
|
||||
t_usize idx;
|
||||
|
||||
if (vec == NULL || fn == NULL)
|
||||
return;
|
||||
return ;
|
||||
idx = 0;
|
||||
while (idx < vec->len)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,23 +10,20 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_buf_str.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_error vec_buf_str_push_front(t_vec_buf_str *vec,
|
||||
t_string element)
|
||||
t_error vec_buf_str_push_front(t_vec_buf_str *vec, t_string element)
|
||||
{
|
||||
t_usize i;
|
||||
t_usize i;
|
||||
|
||||
if (vec->len == 0)
|
||||
return (vec_buf_str_push(vec, element));
|
||||
i = vec->len - 1;
|
||||
if (vec->capacity < vec->len + 1 &&
|
||||
vec_buf_str_reserve(vec, 3 * vec->len / 2 + 1))
|
||||
if (vec->capacity < vec->len + 1 && vec_buf_str_reserve(vec, 3 * vec->len
|
||||
/ 2 + 1))
|
||||
return (ERROR);
|
||||
while (i > 0)
|
||||
{
|
||||
|
|
@ -39,9 +36,9 @@ t_error vec_buf_str_push_front(t_vec_buf_str *vec,
|
|||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
t_error vec_buf_str_pop_front(t_vec_buf_str *vec, t_string *value)
|
||||
t_error vec_buf_str_pop_front(t_vec_buf_str *vec, t_string *value)
|
||||
{
|
||||
t_usize i;
|
||||
t_usize i;
|
||||
|
||||
if (vec->len <= 1)
|
||||
return (vec_buf_str_pop(vec, value));
|
||||
|
|
@ -57,10 +54,10 @@ t_error vec_buf_str_pop_front(t_vec_buf_str *vec, t_string *value)
|
|||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
void vec_buf_str_reverse(t_vec_buf_str *vec)
|
||||
void vec_buf_str_reverse(t_vec_buf_str *vec)
|
||||
{
|
||||
t_string temporary;
|
||||
t_usize i;
|
||||
t_string temporary;
|
||||
t_usize i;
|
||||
|
||||
i = 0;
|
||||
while (i < vec->len / 2)
|
||||
|
|
@ -72,9 +69,9 @@ void vec_buf_str_reverse(t_vec_buf_str *vec)
|
|||
}
|
||||
}
|
||||
|
||||
t_error vec_buf_str_back(t_vec_buf_str *vec, t_string **out)
|
||||
t_error vec_buf_str_back(t_vec_buf_str *vec, t_string **out)
|
||||
{
|
||||
t_string *temporary;
|
||||
t_string *temporary;
|
||||
|
||||
if (out == NULL)
|
||||
out = &temporary;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* vec_str.c :+: :+: :+: */
|
||||
/* str.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/08/01 07:31:20 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,10 +15,9 @@
|
|||
#include "me/vec/vec_str.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_vec_str vec_str_new(t_usize capacity,
|
||||
t_free_str_item free_function)
|
||||
t_vec_str vec_str_new(t_usize capacity, t_free_str_item free_function)
|
||||
{
|
||||
t_vec_str out;
|
||||
t_vec_str out;
|
||||
|
||||
out = (t_vec_str){0};
|
||||
out.free_func = free_function;
|
||||
|
|
@ -29,7 +28,7 @@ t_vec_str vec_str_new(t_usize capacity,
|
|||
}
|
||||
|
||||
/// Return true in case of an error
|
||||
t_error vec_str_push(t_vec_str *vec, t_str element)
|
||||
t_error vec_str_push(t_vec_str *vec, t_str element)
|
||||
{
|
||||
if (vec == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -40,9 +39,9 @@ t_error vec_str_push(t_vec_str *vec, t_str element)
|
|||
}
|
||||
|
||||
/// Return true in case of an error
|
||||
t_error vec_str_reserve(t_vec_str *vec, t_usize wanted_capacity)
|
||||
t_error vec_str_reserve(t_vec_str *vec, t_usize wanted_capacity)
|
||||
{
|
||||
size_t new_capacity;
|
||||
size_t new_capacity;
|
||||
|
||||
if (vec == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -51,8 +50,8 @@ t_error vec_str_reserve(t_vec_str *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_str));
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, \
|
||||
sizeof(t_str));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
return (NO_ERROR);
|
||||
|
|
@ -60,10 +59,10 @@ t_error vec_str_reserve(t_vec_str *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_str_pop(t_vec_str *vec, t_str *value)
|
||||
t_error vec_str_pop(t_vec_str *vec, t_str *value)
|
||||
{
|
||||
t_str temp_value;
|
||||
t_str *ptr;
|
||||
t_str temp_value;
|
||||
t_str *ptr;
|
||||
|
||||
if (vec == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -79,10 +78,10 @@ t_error vec_str_pop(t_vec_str *vec, t_str *value)
|
|||
}
|
||||
|
||||
/// This function is safe to call with `free_elem` being NULL
|
||||
void vec_str_free(t_vec_str vec)
|
||||
void vec_str_free(t_vec_str vec)
|
||||
{
|
||||
if (vec.buffer == NULL)
|
||||
return;
|
||||
return ;
|
||||
if (vec.free_func)
|
||||
{
|
||||
while (vec.len)
|
||||
|
|
|
|||
|
|
@ -10,17 +10,14 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_str.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_error vec_str_find(t_vec_str *vec,
|
||||
bool (*fn)(const t_str *), t_usize *index)
|
||||
t_error vec_str_find(t_vec_str *vec, bool (*fn)(const t_str *), t_usize *index)
|
||||
{
|
||||
t_usize idx;
|
||||
t_usize idx;
|
||||
|
||||
if (vec == NULL || fn == NULL || index == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -37,11 +34,10 @@ t_error vec_str_find(t_vec_str *vec,
|
|||
return (ERROR);
|
||||
}
|
||||
|
||||
t_error vec_str_find_starting(t_vec_str *vec,
|
||||
bool (*fn)(const t_str *),
|
||||
t_usize starting_index, t_usize *index)
|
||||
t_error vec_str_find_starting(t_vec_str *vec, bool (*fn)(const t_str *),
|
||||
t_usize starting_index, t_usize *index)
|
||||
{
|
||||
t_usize idx;
|
||||
t_usize idx;
|
||||
|
||||
if (vec == NULL || fn == NULL || index == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -58,10 +54,9 @@ t_error vec_str_find_starting(t_vec_str *vec,
|
|||
return (ERROR);
|
||||
}
|
||||
|
||||
t_error vec_str_all(t_vec_str *vec,
|
||||
bool (*fn)(const t_str *), bool *result)
|
||||
t_error vec_str_all(t_vec_str *vec, bool (*fn)(const t_str *), bool *result)
|
||||
{
|
||||
t_usize idx;
|
||||
t_usize idx;
|
||||
|
||||
if (vec == NULL || fn == NULL || result == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -76,10 +71,9 @@ t_error vec_str_all(t_vec_str *vec,
|
|||
return (ERROR);
|
||||
}
|
||||
|
||||
t_error vec_str_any(t_vec_str *vec,
|
||||
bool (*fn)(const t_str *), bool *result)
|
||||
t_error vec_str_any(t_vec_str *vec, bool (*fn)(const t_str *), bool *result)
|
||||
{
|
||||
t_usize idx;
|
||||
t_usize idx;
|
||||
|
||||
if (vec == NULL || fn == NULL || result == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -94,15 +88,13 @@ t_error vec_str_any(t_vec_str *vec,
|
|||
return (ERROR);
|
||||
}
|
||||
|
||||
void vec_str_iter(t_vec_str *vec,
|
||||
void (*fn)(t_usize index, t_str *value,
|
||||
void *state),
|
||||
void *state)
|
||||
void vec_str_iter(t_vec_str *vec, void (*fn)(t_usize index, t_str *value,
|
||||
void *state), void *state)
|
||||
{
|
||||
t_usize idx;
|
||||
t_usize idx;
|
||||
|
||||
if (vec == NULL || fn == NULL)
|
||||
return;
|
||||
return ;
|
||||
idx = 0;
|
||||
while (idx < vec->len)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,23 +10,20 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_str.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_error vec_str_push_front(t_vec_str *vec,
|
||||
t_str element)
|
||||
t_error vec_str_push_front(t_vec_str *vec, t_str element)
|
||||
{
|
||||
t_usize i;
|
||||
t_usize i;
|
||||
|
||||
if (vec->len == 0)
|
||||
return (vec_str_push(vec, element));
|
||||
i = vec->len - 1;
|
||||
if (vec->capacity < vec->len + 1 &&
|
||||
vec_str_reserve(vec, 3 * vec->len / 2 + 1))
|
||||
if (vec->capacity < vec->len + 1 && vec_str_reserve(vec, 3 * vec->len / 2
|
||||
+ 1))
|
||||
return (ERROR);
|
||||
while (i > 0)
|
||||
{
|
||||
|
|
@ -39,9 +36,9 @@ t_error vec_str_push_front(t_vec_str *vec,
|
|||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
t_error vec_str_pop_front(t_vec_str *vec, t_str *value)
|
||||
t_error vec_str_pop_front(t_vec_str *vec, t_str *value)
|
||||
{
|
||||
t_usize i;
|
||||
t_usize i;
|
||||
|
||||
if (vec->len <= 1)
|
||||
return (vec_str_pop(vec, value));
|
||||
|
|
@ -57,10 +54,10 @@ t_error vec_str_pop_front(t_vec_str *vec, t_str *value)
|
|||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
void vec_str_reverse(t_vec_str *vec)
|
||||
void vec_str_reverse(t_vec_str *vec)
|
||||
{
|
||||
t_str temporary;
|
||||
t_usize i;
|
||||
t_str temporary;
|
||||
t_usize i;
|
||||
|
||||
i = 0;
|
||||
while (i < vec->len / 2)
|
||||
|
|
@ -72,9 +69,9 @@ void vec_str_reverse(t_vec_str *vec)
|
|||
}
|
||||
}
|
||||
|
||||
t_error vec_str_back(t_vec_str *vec, t_str **out)
|
||||
t_error vec_str_back(t_vec_str *vec, t_str **out)
|
||||
{
|
||||
t_str *temporary;
|
||||
t_str *temporary;
|
||||
|
||||
if (out == NULL)
|
||||
out = &temporary;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* vec_u8.c :+: :+: :+: */
|
||||
/* u8.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/08/01 07:31:34 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,10 +15,9 @@
|
|||
#include "me/vec/vec_u8.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_vec_u8 vec_u8_new(t_usize capacity,
|
||||
t_free_u8_item free_function)
|
||||
t_vec_u8 vec_u8_new(t_usize capacity, t_free_u8_item free_function)
|
||||
{
|
||||
t_vec_u8 out;
|
||||
t_vec_u8 out;
|
||||
|
||||
out = (t_vec_u8){0};
|
||||
out.free_func = free_function;
|
||||
|
|
@ -29,7 +28,7 @@ t_vec_u8 vec_u8_new(t_usize capacity,
|
|||
}
|
||||
|
||||
/// Return true in case of an error
|
||||
t_error vec_u8_push(t_vec_u8 *vec, t_u8 element)
|
||||
t_error vec_u8_push(t_vec_u8 *vec, t_u8 element)
|
||||
{
|
||||
if (vec == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -40,9 +39,9 @@ t_error vec_u8_push(t_vec_u8 *vec, t_u8 element)
|
|||
}
|
||||
|
||||
/// Return true in case of an error
|
||||
t_error vec_u8_reserve(t_vec_u8 *vec, t_usize wanted_capacity)
|
||||
t_error vec_u8_reserve(t_vec_u8 *vec, t_usize wanted_capacity)
|
||||
{
|
||||
size_t new_capacity;
|
||||
size_t new_capacity;
|
||||
|
||||
if (vec == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -51,8 +50,8 @@ t_error vec_u8_reserve(t_vec_u8 *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_u8));
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, \
|
||||
sizeof(t_u8));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
return (NO_ERROR);
|
||||
|
|
@ -60,10 +59,10 @@ t_error vec_u8_reserve(t_vec_u8 *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_u8_pop(t_vec_u8 *vec, t_u8 *value)
|
||||
t_error vec_u8_pop(t_vec_u8 *vec, t_u8 *value)
|
||||
{
|
||||
t_u8 temp_value;
|
||||
t_u8 *ptr;
|
||||
t_u8 temp_value;
|
||||
t_u8 *ptr;
|
||||
|
||||
if (vec == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -79,10 +78,10 @@ t_error vec_u8_pop(t_vec_u8 *vec, t_u8 *value)
|
|||
}
|
||||
|
||||
/// This function is safe to call with `free_elem` being NULL
|
||||
void vec_u8_free(t_vec_u8 vec)
|
||||
void vec_u8_free(t_vec_u8 vec)
|
||||
{
|
||||
if (vec.buffer == NULL)
|
||||
return;
|
||||
return ;
|
||||
if (vec.free_func)
|
||||
{
|
||||
while (vec.len)
|
||||
|
|
|
|||
|
|
@ -10,17 +10,14 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_u8.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_error vec_u8_find(t_vec_u8 *vec,
|
||||
bool (*fn)(const t_u8 *), t_usize *index)
|
||||
t_error vec_u8_find(t_vec_u8 *vec, bool (*fn)(const t_u8 *), t_usize *index)
|
||||
{
|
||||
t_usize idx;
|
||||
t_usize idx;
|
||||
|
||||
if (vec == NULL || fn == NULL || index == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -37,11 +34,10 @@ t_error vec_u8_find(t_vec_u8 *vec,
|
|||
return (ERROR);
|
||||
}
|
||||
|
||||
t_error vec_u8_find_starting(t_vec_u8 *vec,
|
||||
bool (*fn)(const t_u8 *),
|
||||
t_usize starting_index, t_usize *index)
|
||||
t_error vec_u8_find_starting(t_vec_u8 *vec, bool (*fn)(const t_u8 *),
|
||||
t_usize starting_index, t_usize *index)
|
||||
{
|
||||
t_usize idx;
|
||||
t_usize idx;
|
||||
|
||||
if (vec == NULL || fn == NULL || index == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -58,10 +54,9 @@ t_error vec_u8_find_starting(t_vec_u8 *vec,
|
|||
return (ERROR);
|
||||
}
|
||||
|
||||
t_error vec_u8_all(t_vec_u8 *vec,
|
||||
bool (*fn)(const t_u8 *), bool *result)
|
||||
t_error vec_u8_all(t_vec_u8 *vec, bool (*fn)(const t_u8 *), bool *result)
|
||||
{
|
||||
t_usize idx;
|
||||
t_usize idx;
|
||||
|
||||
if (vec == NULL || fn == NULL || result == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -76,10 +71,9 @@ t_error vec_u8_all(t_vec_u8 *vec,
|
|||
return (ERROR);
|
||||
}
|
||||
|
||||
t_error vec_u8_any(t_vec_u8 *vec,
|
||||
bool (*fn)(const t_u8 *), bool *result)
|
||||
t_error vec_u8_any(t_vec_u8 *vec, bool (*fn)(const t_u8 *), bool *result)
|
||||
{
|
||||
t_usize idx;
|
||||
t_usize idx;
|
||||
|
||||
if (vec == NULL || fn == NULL || result == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -94,15 +88,13 @@ t_error vec_u8_any(t_vec_u8 *vec,
|
|||
return (ERROR);
|
||||
}
|
||||
|
||||
void vec_u8_iter(t_vec_u8 *vec,
|
||||
void (*fn)(t_usize index, t_u8 *value,
|
||||
void *state),
|
||||
void *state)
|
||||
void vec_u8_iter(t_vec_u8 *vec, void (*fn)(t_usize index, t_u8 *value,
|
||||
void *state), void *state)
|
||||
{
|
||||
t_usize idx;
|
||||
t_usize idx;
|
||||
|
||||
if (vec == NULL || fn == NULL)
|
||||
return;
|
||||
return ;
|
||||
idx = 0;
|
||||
while (idx < vec->len)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,23 +10,20 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_u8.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_error vec_u8_push_front(t_vec_u8 *vec,
|
||||
t_u8 element)
|
||||
t_error vec_u8_push_front(t_vec_u8 *vec, t_u8 element)
|
||||
{
|
||||
t_usize i;
|
||||
t_usize i;
|
||||
|
||||
if (vec->len == 0)
|
||||
return (vec_u8_push(vec, element));
|
||||
i = vec->len - 1;
|
||||
if (vec->capacity < vec->len + 1 &&
|
||||
vec_u8_reserve(vec, 3 * vec->len / 2 + 1))
|
||||
if (vec->capacity < vec->len + 1 && vec_u8_reserve(vec, 3 * vec->len / 2
|
||||
+ 1))
|
||||
return (ERROR);
|
||||
while (i > 0)
|
||||
{
|
||||
|
|
@ -39,9 +36,9 @@ t_error vec_u8_push_front(t_vec_u8 *vec,
|
|||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
t_error vec_u8_pop_front(t_vec_u8 *vec, t_u8 *value)
|
||||
t_error vec_u8_pop_front(t_vec_u8 *vec, t_u8 *value)
|
||||
{
|
||||
t_usize i;
|
||||
t_usize i;
|
||||
|
||||
if (vec->len <= 1)
|
||||
return (vec_u8_pop(vec, value));
|
||||
|
|
@ -57,10 +54,10 @@ t_error vec_u8_pop_front(t_vec_u8 *vec, t_u8 *value)
|
|||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
void vec_u8_reverse(t_vec_u8 *vec)
|
||||
void vec_u8_reverse(t_vec_u8 *vec)
|
||||
{
|
||||
t_u8 temporary;
|
||||
t_usize i;
|
||||
t_u8 temporary;
|
||||
t_usize i;
|
||||
|
||||
i = 0;
|
||||
while (i < vec->len / 2)
|
||||
|
|
@ -72,9 +69,9 @@ void vec_u8_reverse(t_vec_u8 *vec)
|
|||
}
|
||||
}
|
||||
|
||||
t_error vec_u8_back(t_vec_u8 *vec, t_u8 **out)
|
||||
t_error vec_u8_back(t_vec_u8 *vec, t_u8 **out)
|
||||
{
|
||||
t_u8 *temporary;
|
||||
t_u8 *temporary;
|
||||
|
||||
if (out == NULL)
|
||||
out = &temporary;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue