Added env hashmap with build_env function to build envp

This commit is contained in:
Maix0 2024-05-04 19:21:56 +02:00
parent f35e986145
commit f86947a852
54 changed files with 2010 additions and 105 deletions

View file

@ -73,4 +73,10 @@ t_entry_C__PREFIX__ *hashmap_get_entry_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap,
C__KEYTYPE__ *key,
t_entry_C__PREFIX__ **prev);
t_error hashmap_C__PREFIX___iter(t_hashmap_C__PREFIX__ *self,
t_error (*func)(t_usize idx,
const C__KEYTYPE__ *key,
C__VALTYPE__ *val, void *ctx),
void *ctx);
#endif

View file

@ -102,9 +102,9 @@ void insert_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ key,
entry = hashmap_get_entry_C__PREFIX__(hmap, hashed_key, &key, &prev);
if (entry == NULL)
{
entry = mem_alloc(sizeof(t_entry_tile));
entry = mem_alloc(sizeof(t_entry_C__PREFIX__));
entry->hash_id = hashed_key;
entry->kv = (t_kv_tile){.key = key, .val = value};
entry->kv = (t_kv_C__PREFIX__){.key = key, .val = value};
entry->next = NULL;
if (prev == NULL)
hmap->buckets[hashed_key % hmap->num_buckets] = entry;

View file

@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hashmap_C__PREFIX__.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/hashmap/hashmap_C__PREFIX__.h"
t_error hashmap_C__PREFIX___iter(t_hashmap_C__PREFIX__ *self,
t_error (*func)(t_usize idx,
const C__KEYTYPE__ *key,
C__VALTYPE__ *val, void *ctx),
void *ctx)
{
t_usize bucket_id;
t_usize all_id;
t_entry_C__PREFIX__ *cur;
bucket_id = 0;
all_id = 0;
while (bucket_id < self->num_buckets)
{
cur = self->buckets[bucket_id];
while (cur != NULL)
{
if (func(all_id++, &cur->kv.key, &cur->kv.val, ctx))
return (ERROR);
cur = cur->next;
}
bucket_id++;
}
return (NO_ERROR);
}

View file

@ -27,7 +27,7 @@ C__VALTYPE__ *get_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap,
hmap->hfunc(&hmap->hasher, key);
hashed_key = hasher_reset_and_finish(&hmap->hasher);
entry = hashmap_get_entry_tile(hmap, hashed_key, key, &prev);
entry = hashmap_get_entry_C__PREFIX__(hmap, hashed_key, key, &prev);
if (entry == NULL)
return (NULL);
return (&entry->kv.val);