#ifndef __SAFEC_MAP_H
#define __SAFEC_MAP_H
#include "types.h"
#include "hash.h"

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);

typedef void (*map_foreach_func_t)(void* key, void* val, void* data);
void map_foreach_readonly(
    map_t* map,
    map_foreach_func_t foreach_func,
    void* data);
void map_foreach_readwrite(
    map_t* map,
    map_foreach_func_t foreach_func,
    void* data);

#endif
