#ifndef __SAFEC_MAP_H
#include "types.h"

typedef size_t (*hash_func_t)(const void*);
typedef bool (*eq_func_t)(const void*, const void*);

struct __map_entry {
    void* key;
    void* value;
    struct __map_entry* next;
};

typedef struct {
    hash_func_t hash_func;
    eq_func_t eq_func;
    double load_limit;

    size_t size;

    size_t __num_buckets;
    struct __map_entry* __buckets;
} map_t;

void map_init(
    map_t* map,
    hash_func_t hash_func,
    eq_func_t eq_func,
    double load_limit);
void map_init_capacity(
    map_t* map,
    hash_func_t hash_func,
    eq_func_t eq_func,
    double load_limit,
    size_t capacity);
void map_destroy(map_t* map);

bool map_contains(const map_t* map, const void* key);
void* map_get(const map_t* map, const void* key);
void* map_get_or_default(const map_t* map, const void* key, void* default_val);
void* map_compute_if_absent(map_t* map, void* key, void* default_val);
void map_put(map_t* map, void* key, void* val);
void* map_remove(map_t* map, const void* key);

#endif
