This commit is contained in:
Maix0 2024-05-18 16:42:03 +02:00
parent 5d2202a0c9
commit 1d7112f982
14 changed files with 54 additions and 91 deletions

View file

@ -13,8 +13,7 @@
#include "me/hash/hasher.h"
#include "me/hash/sip.h"
#include "me/hashmap/hashmap_C__PREFIX__.h"
#include "me/mem/mem_alloc.h"
#include "me/mem/mem_alloc_array.h"
#include "me/mem/mem.h"
#include "me/mem/mem_copy.h"
#include "me/types.h"
#include <stdlib.h>

View file

@ -12,8 +12,7 @@
#include "me/hash/sip.h"
#include "me/hashmap/hashmap_C__PREFIX__.h"
#include "me/mem/mem_alloc.h"
#include "me/mem/mem_alloc_array.h"
#include "me/mem/mem.h"
#include "me/mem/mem_copy.h"
#include "me/types.h"
#include <stdlib.h>

View file

@ -34,18 +34,9 @@ t_vec_C__PREFIX__ vec_C__PREFIX___new(t_usize capacity,
/// Return true in case of an error
t_error vec_C__PREFIX___push(t_vec_C__PREFIX__ *vec, C__TYPENAME__ element)
{
size_t new_capacity;
if (vec == NULL)
return (ERROR);
if (vec->len + 1 > vec->capacity)
{
new_capacity = (vec->capacity * 3) / 2 + 1;
while (vec->len + 1 > new_capacity)
new_capacity = (new_capacity * 3) / 2 + 1;
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(C__TYPENAME__));
vec->capacity = new_capacity;
}
vec_C__PREFIX___reserve(vec, vec->len + 1);
vec->buffer[vec->len] = element;
vec->len += 1;
return (NO_ERROR);

View file

@ -6,23 +6,23 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 16:05:48 by maiboyer #+# #+# */
/* Updated: 2023/12/09 18:15:57 by maiboyer ### ########.fr */
/* Updated: 2024/05/18 16:34:33 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/mem_alloc.h"
#include "me/string/str_clone.h"
#include "me/mem/mem.h"
#include "me/string/str_l_copy.h"
#include "me/string/str_len.h"
#include <stdlib.h>
t_str str_clone(t_const_str source)
t_str str_clone(t_const_str source)
{
t_str res;
t_usize len;
t_usize len;
len = str_len(source) + 1;
res = mem_alloc(sizeof(unsigned char) * len);
res = mem_alloc_array(sizeof(*res), len);
if (res == NULL)
return (NULL);
str_l_copy(res, source, len);