update stuff
This commit is contained in:
parent
24b210fe86
commit
709c124028
20 changed files with 176 additions and 64 deletions
12
output/src/hashmap/env/env.c
vendored
12
output/src/hashmap/env/env.c
vendored
|
|
@ -19,15 +19,15 @@
|
|||
|
||||
t_hashmap_env *hmap_env_new(t_hash_env_fn hfunc,
|
||||
t_eq_env_fn cfunc,
|
||||
t_drop_env_fn drop)
|
||||
t_free_env_fn free)
|
||||
{
|
||||
return (
|
||||
hmap_env_new_with_buckets(hfunc, cfunc, drop, DEFAULT_BUCKETS));
|
||||
hmap_env_new_with_buckets(hfunc, cfunc, free, DEFAULT_BUCKETS));
|
||||
}
|
||||
|
||||
t_hashmap_env *hmap_env_new_with_buckets(
|
||||
t_hash_env_fn hfunc, t_eq_env_fn cfunc,
|
||||
t_drop_env_fn drop, t_usize buckets)
|
||||
t_free_env_fn free, t_usize buckets)
|
||||
{
|
||||
t_hashmap_env *hmap;
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ t_hashmap_env *hmap_env_new_with_buckets(
|
|||
hmap->hasher = hasher_sip13_new();
|
||||
hmap->hfunc = hfunc;
|
||||
hmap->cfunc = cfunc;
|
||||
hmap->drop = drop;
|
||||
hmap->free = free;
|
||||
if (hmap->buckets == NULL)
|
||||
return ((void)mem_free(hmap), NULL);
|
||||
return (hmap);
|
||||
|
|
@ -57,7 +57,7 @@ void hmap_env_free(t_hashmap_env *hmap)
|
|||
entry = hmap->buckets[index];
|
||||
while (entry != NULL)
|
||||
{
|
||||
hmap->drop(entry->kv);
|
||||
hmap->free(entry->kv);
|
||||
tmp = entry->next;
|
||||
mem_free(entry);
|
||||
entry = tmp;
|
||||
|
|
@ -117,7 +117,7 @@ bool hmap_env_insert(t_hashmap_env *hmap, t_str key,
|
|||
}
|
||||
else
|
||||
{
|
||||
hmap->drop(entry->kv);
|
||||
hmap->free(entry->kv);
|
||||
entry->kv.key = key;
|
||||
entry->kv.val = value;
|
||||
return (true);
|
||||
|
|
|
|||
40
output/src/hashmap/env/env_clear.c
vendored
Normal file
40
output/src/hashmap/env/env_clear.c
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* hashmap_env.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/06 11:00:22 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/11 15:24:44 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/types.h"
|
||||
|
||||
|
||||
|
||||
#include "me/hashmap/hashmap_env.h"
|
||||
#include "me/mem/mem.h"
|
||||
|
||||
|
||||
void hmap_env_clear(t_hashmap_env *self)
|
||||
{
|
||||
t_usize bucket_id;
|
||||
t_entry_env *cur;
|
||||
t_entry_env *next;
|
||||
|
||||
bucket_id = 0;
|
||||
while (bucket_id < self->num_buckets)
|
||||
{
|
||||
cur = self->buckets[bucket_id];
|
||||
while (cur != NULL)
|
||||
{
|
||||
next = cur->next;
|
||||
self->free(cur->kv);
|
||||
mem_free(cur);
|
||||
cur = next;
|
||||
}
|
||||
bucket_id++;
|
||||
}
|
||||
}
|
||||
2
output/src/hashmap/env/env_clone.c
vendored
2
output/src/hashmap/env/env_clone.c
vendored
|
|
@ -27,7 +27,7 @@ t_error hmap_env_clone(t_hashmap_env *self,
|
|||
t_hashmap_env *ret;
|
||||
|
||||
bucket_id = 0;
|
||||
ret = hmap_env_new_with_buckets(self->hfunc, self->cfunc, self->drop, self->num_buckets);
|
||||
ret = hmap_env_new_with_buckets(self->hfunc, self->cfunc, self->free, self->num_buckets);
|
||||
if (ret == NULL)
|
||||
return (ERROR);
|
||||
while (bucket_id < self->num_buckets)
|
||||
|
|
|
|||
2
output/src/hashmap/env/env_utils.c
vendored
2
output/src/hashmap/env/env_utils.c
vendored
|
|
@ -48,7 +48,7 @@ void hmap_env_remove(t_hashmap_env *hmap, t_str *key)
|
|||
hmap->buckets[hashed_key % hmap->num_buckets] = entry->next;
|
||||
else
|
||||
prev->next = entry->next;
|
||||
hmap->drop(entry->kv);
|
||||
hmap->free(entry->kv);
|
||||
mem_free(entry);
|
||||
hmap->buckets[hashed_key % hmap->num_buckets] = NULL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue