normed: output directory
This commit is contained in:
parent
7bb95e24a6
commit
3d11b63428
37 changed files with 692 additions and 708 deletions
50
output/src/hashmap/env/env.c
vendored
50
output/src/hashmap/env/env.c
vendored
|
|
@ -1,12 +1,12 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* hashmap_env.c :+: :+: :+: */
|
||||
/* env.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/06 10:58:20 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/11 15:32:51 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/12 15:43:01 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,19 +17,16 @@
|
|||
#include "me/types.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_hashmap_env *hmap_env_new(t_hash_env_fn hfunc,
|
||||
t_eq_env_fn cfunc,
|
||||
t_free_env_fn free)
|
||||
t_hashmap_env *hmap_env_new(t_hash_env_fn hfunc, t_eq_env_fn cfunc,
|
||||
t_free_env_fn free)
|
||||
{
|
||||
return (
|
||||
hmap_env_new_with_buckets(hfunc, cfunc, free, DEFAULT_BUCKETS));
|
||||
return (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_free_env_fn free, t_usize buckets)
|
||||
t_hashmap_env *hmap_env_new_with_buckets(t_hash_env_fn hfunc,
|
||||
t_eq_env_fn cfunc, t_free_env_fn free, t_usize buckets)
|
||||
{
|
||||
t_hashmap_env *hmap;
|
||||
t_hashmap_env *hmap;
|
||||
|
||||
hmap = mem_alloc(sizeof(*hmap));
|
||||
if (hmap == NULL)
|
||||
|
|
@ -45,11 +42,11 @@ t_hashmap_env *hmap_env_new_with_buckets(
|
|||
return (hmap);
|
||||
}
|
||||
|
||||
void hmap_env_free(t_hashmap_env *hmap)
|
||||
void hmap_env_free(t_hashmap_env *hmap)
|
||||
{
|
||||
t_usize index;
|
||||
t_entry_env *entry;
|
||||
t_entry_env *tmp;
|
||||
t_usize index;
|
||||
t_entry_env *entry;
|
||||
t_entry_env *tmp;
|
||||
|
||||
index = 0;
|
||||
while (index < hmap->num_buckets)
|
||||
|
|
@ -69,12 +66,10 @@ void hmap_env_free(t_hashmap_env *hmap)
|
|||
mem_free(hmap);
|
||||
}
|
||||
|
||||
t_entry_env *hmap_env_get_entry(t_hashmap_env *hmap,
|
||||
t_usize hashed_key,
|
||||
t_str *key,
|
||||
t_entry_env **prev)
|
||||
t_entry_env *hmap_env_get_entry(t_hashmap_env *hmap, t_usize hashed_key,
|
||||
t_str *key, t_entry_env **prev)
|
||||
{
|
||||
t_entry_env *entry;
|
||||
t_entry_env *entry;
|
||||
|
||||
entry = hmap->buckets[hashed_key % hmap->num_buckets];
|
||||
while (entry != NULL)
|
||||
|
|
@ -92,12 +87,11 @@ t_entry_env *hmap_env_get_entry(t_hashmap_env *hmap,
|
|||
return (NULL);
|
||||
}
|
||||
|
||||
bool hmap_env_insert(t_hashmap_env *hmap, t_str key,
|
||||
t_str value)
|
||||
bool hmap_env_insert(t_hashmap_env *hmap, t_str key, t_str value)
|
||||
{
|
||||
t_usize hashed_key;
|
||||
t_entry_env *prev;
|
||||
t_entry_env *entry;
|
||||
t_usize hashed_key;
|
||||
t_entry_env *prev;
|
||||
t_entry_env *entry;
|
||||
|
||||
hmap->hfunc(&hmap->hasher, &key);
|
||||
hashed_key = hasher_reset_and_finish(&hmap->hasher);
|
||||
|
|
@ -117,9 +111,7 @@ bool hmap_env_insert(t_hashmap_env *hmap, t_str key,
|
|||
}
|
||||
else
|
||||
{
|
||||
hmap->free(entry->kv);
|
||||
entry->kv.key = key;
|
||||
entry->kv.val = value;
|
||||
return (true);
|
||||
entry->kv.key = (hmap->free(entry->kv), key);
|
||||
return (entry->kv.val = value, true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
12
output/src/hashmap/env/env_clear.c
vendored
12
output/src/hashmap/env/env_clear.c
vendored
|
|
@ -10,19 +10,15 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/types.h"
|
||||
|
||||
|
||||
|
||||
#include "me/hashmap/hashmap_env.h"
|
||||
#include "me/mem/mem.h"
|
||||
|
||||
#include "me/types.h"
|
||||
|
||||
void hmap_env_clear(t_hashmap_env *self)
|
||||
{
|
||||
t_usize bucket_id;
|
||||
t_entry_env *cur;
|
||||
t_entry_env *next;
|
||||
t_usize bucket_id;
|
||||
t_entry_env *cur;
|
||||
t_entry_env *next;
|
||||
|
||||
bucket_id = 0;
|
||||
while (bucket_id < self->num_buckets)
|
||||
|
|
|
|||
19
output/src/hashmap/env/env_clone.c
vendored
19
output/src/hashmap/env/env_clone.c
vendored
|
|
@ -10,24 +10,21 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/hashmap/hashmap_env.h"
|
||||
#include "me/types.h"
|
||||
|
||||
#include "me/hashmap/hashmap_env.h"
|
||||
|
||||
|
||||
|
||||
t_error hmap_env_clone(t_hashmap_env *self,
|
||||
t_error (*clone)(const t_kv_env *val, void *ctx, t_kv_env *out),
|
||||
void *ctx,
|
||||
t_hashmap_env **out)
|
||||
t_error hmap_env_clone(t_hashmap_env *self,
|
||||
t_error (*clone)(const t_kv_env *val, void *ctx, t_kv_env *out),
|
||||
void *ctx, t_hashmap_env **out)
|
||||
{
|
||||
t_usize bucket_id;
|
||||
t_usize bucket_id;
|
||||
t_entry_env *cur;
|
||||
t_kv_env kv;
|
||||
t_hashmap_env *ret;
|
||||
|
||||
bucket_id = 0;
|
||||
ret = hmap_env_new_with_buckets(self->hfunc, self->cfunc, self->free, 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)
|
||||
|
|
@ -36,7 +33,7 @@ t_error hmap_env_clone(t_hashmap_env *self,
|
|||
while (cur != NULL)
|
||||
{
|
||||
if (clone(&cur->kv, ctx, &kv))
|
||||
return (hmap_env_free(ret),ERROR);
|
||||
return (hmap_env_free(ret), ERROR);
|
||||
hmap_env_insert(ret, kv.key, kv.val);
|
||||
cur = cur->next;
|
||||
}
|
||||
|
|
|
|||
13
output/src/hashmap/env/env_iter.c
vendored
13
output/src/hashmap/env/env_iter.c
vendored
|
|
@ -12,15 +12,12 @@
|
|||
|
||||
#include "me/hashmap/hashmap_env.h"
|
||||
|
||||
t_error hmap_env_iter(t_hashmap_env *self,
|
||||
t_error (*func)(t_usize idx,
|
||||
const t_str *key,
|
||||
t_str *val, void *ctx),
|
||||
void *ctx)
|
||||
t_error hmap_env_iter(t_hashmap_env *self, t_error (*func)(t_usize idx,
|
||||
const t_str *key, t_str *val, void *ctx), void *ctx)
|
||||
{
|
||||
t_usize bucket_id;
|
||||
t_usize all_id;
|
||||
t_entry_env *cur;
|
||||
t_usize bucket_id;
|
||||
t_usize all_id;
|
||||
t_entry_env *cur;
|
||||
|
||||
bucket_id = 0;
|
||||
all_id = 0;
|
||||
|
|
|
|||
19
output/src/hashmap/env/env_utils.c
vendored
19
output/src/hashmap/env/env_utils.c
vendored
|
|
@ -16,12 +16,11 @@
|
|||
#include "me/types.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_str *hmap_env_get(t_hashmap_env *hmap,
|
||||
t_str *key)
|
||||
t_str *hmap_env_get(t_hashmap_env *hmap, t_str *key)
|
||||
{
|
||||
t_usize hashed_key;
|
||||
t_entry_env *entry;
|
||||
t_entry_env *prev;
|
||||
t_usize hashed_key;
|
||||
t_entry_env *entry;
|
||||
t_entry_env *prev;
|
||||
|
||||
hmap->hfunc(&hmap->hasher, key);
|
||||
hashed_key = hasher_reset_and_finish(&hmap->hasher);
|
||||
|
|
@ -31,18 +30,18 @@ t_str *hmap_env_get(t_hashmap_env *hmap,
|
|||
return (&entry->kv.val);
|
||||
}
|
||||
|
||||
void hmap_env_remove(t_hashmap_env *hmap, t_str *key)
|
||||
void hmap_env_remove(t_hashmap_env *hmap, t_str *key)
|
||||
{
|
||||
t_usize hashed_key;
|
||||
t_entry_env *prev;
|
||||
t_entry_env *entry;
|
||||
t_usize hashed_key;
|
||||
t_entry_env *prev;
|
||||
t_entry_env *entry;
|
||||
|
||||
hmap->hfunc(&hmap->hasher, key);
|
||||
hashed_key = hasher_reset_and_finish(&hmap->hasher);
|
||||
prev = NULL;
|
||||
entry = hmap_env_get_entry(hmap, hashed_key, key, &prev);
|
||||
if (entry == NULL)
|
||||
return;
|
||||
return ;
|
||||
if (prev == NULL)
|
||||
hmap->buckets[hashed_key % hmap->num_buckets] = entry->next;
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue