summaryrefslogtreecommitdiff
path: root/hashmap.h
blob: ff52eb29f0b4a509b82b7a2a4840bdfb4cf58607 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#ifndef HASHMAP_H
#define HASHMAP_H

#include "ccc.h"

#define ADVANCE_HASH(hash, val, cap) (hash = ((hash << 5) - hash + val) % cap)

typedef integral_t (*hm_hash_fn)(const void*, integral_t);
typedef bool (*hm_eq_fn)(const void*, const void*);
typedef void (*hm_destroy_fn)(void*);

struct hash_map {
    void** entries;
    integral_t cap;

    hm_hash_fn hash_fn;
    hm_eq_fn eq_fn;
    hm_destroy_fn destroy_fn;
};

void hm_init(struct hash_map*, hm_hash_fn, hm_eq_fn, hm_destroy_fn);
void hm_destroy(struct hash_map*);
void** hm_cell_r(const struct hash_map*, const void*);
void** hm_cell_w(struct hash_map*, const void*);

#endif