forked from cblach/nikola-v2gstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.h
50 lines (42 loc) · 723 Bytes
/
map.h
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef MAP_H
#define MAP_H
#include <stdlib.h>
#include <inttypes.h>
typedef union Key Key;
typedef struct Bucket Bucket;
typedef struct Map Map;
union Key
{
int i;
unsigned u;
uint64_t u64;
size_t sz;
ssize_t ssz;
void *ptr;
};
struct Bucket
{
Bucket *next;
Key k;
char v[];
};
struct Map
{
size_t elemsz;
size_t nbuckets;
Bucket **buckets;
size_t (*hash)(Key);
int (*cmp)(Key, Key);
};
int mapinit(Map *map,
size_t elemsz,
size_t nbuckets,
size_t (*hash)(Key),
int (*cmp)(Key, Key));
void *mapinsert(Map *map,
Key k);
void *mapfind(Map *map,
Key k);
void mapremove(Map *map,
Key k);
#endif