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

@ -0,0 +1,82 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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 */
/* */
/* ************************************************************************** */
#ifndef HASHMAP_ENV_H
#define HASHMAP_ENV_H
#define DEFAULT_BUCKETS 750
#include "me/hash/hasher.h"
#include "me/types.h"
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct s_kv_env
{
t_str key;
t_str val;
} t_kv_env;
typedef void (*t_hash_env_fn)(t_hasher *hasher, t_str *key);
typedef void (*t_drop_env_fn)(t_kv_env val);
typedef bool (*t_eq_env_fn)(t_str *lhs, t_str *rhs);
typedef struct s_entry_env
{
t_usize hash_id;
t_kv_env kv;
struct s_entry_env *next;
} t_entry_env;
typedef struct s_hashmap_env
{
t_entry_env **buckets;
t_usize num_buckets;
t_hasher hasher;
t_hash_env_fn hfunc;
t_eq_env_fn cfunc;
t_drop_env_fn drop;
} t_hashmap_env;
t_hashmap_env *new_hashmap_env(t_hash_env_fn hash,
t_eq_env_fn cmp,
t_drop_env_fn drop);
t_hashmap_env *new_hashmap_with_buckets_env(
t_hash_env_fn hash, t_eq_env_fn cmp,
t_drop_env_fn drop, size_t cap);
void drop_hashmap_env(t_hashmap_env *hmap);
void insert_hashmap_env(t_hashmap_env *hmap, t_str key,
t_str value);
t_str *get_hashmap_env(t_hashmap_env *hmap,
t_str *key);
void remove_hashmap_env(t_hashmap_env *hmap, t_str *key);
t_entry_env *hashmap_get_entry_env(t_hashmap_env *hmap,
t_usize hash,
t_str *key,
t_entry_env **prev);
t_error hashmap_env_iter(t_hashmap_env *self,
t_error (*func)(t_usize idx,
const t_str *key,
t_str *val, void *ctx),
void *ctx);
#endif

View file

@ -0,0 +1,58 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vec_str.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/04 18:46:53 by maiboyer #+# #+# */
/* Updated: 2023/12/09 17:53:00 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef VEC_STR_H
#define VEC_STR_H
#include "me/types.h"
typedef bool (*t_vec_str_sort_fn)(t_str *, t_str *);
typedef void (*t_free_str_item)(t_str);
typedef struct s_vec_str
{
t_free_str_item free_func;
t_usize len;
t_usize capacity;
t_str *buffer;
} t_vec_str;
t_vec_str vec_str_new(t_usize capacity,
t_free_str_item free_function);
t_error vec_str_push(t_vec_str *vec, t_str element);
t_error vec_str_push_front(t_vec_str *vec,
t_str element);
t_error vec_str_pop(t_vec_str *vec, t_str *value);
t_error vec_str_pop_front(t_vec_str *vec, t_str *value);
void vec_str_free(t_vec_str vec);
t_error vec_str_reserve(t_vec_str *vec,
t_usize wanted_capacity);
t_error vec_str_find(t_vec_str *vec,
bool (*fn)(const t_str *), 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_error vec_str_all(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);
void vec_str_iter(t_vec_str *vec,
void (*fn)(t_usize index, t_str *value,
void *state),
void *state);
void vec_str_reverse(t_vec_str *vec);
void vec_str_sort(t_vec_str *vec,
t_vec_str_sort_fn is_sorted);
t_error vec_str_back(t_vec_str *vec, t_str **out);
#endif