-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdmap.h
More file actions
40 lines (32 loc) · 718 Bytes
/
Copy pathdmap.h
File metadata and controls
40 lines (32 loc) · 718 Bytes
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
/*
* Copyright Ted Meyer 2015
*
* see LICENSE for details
*
*/
#ifndef _DMAP_H_
#define _DMAP_H_
#define DEFAULT_SIZE 10
#define map_each(m, k, v) \
for(unsigned int i=0;i<(m)->size;i++) \
for(kvpl*itr=((m)->body)[i];itr;itr=itr->next) \
for((k)=itr->kvp->key,(v)=itr->kvp->val;(k);(k)=0,v=0)
struct kvp {
char *key;
void *val;
};
typedef
struct kvpl {
struct kvp *kvp;
struct kvpl *next;
} kvpl;
typedef
struct map {
struct kvpl **body; // null terminated list of KVPs
unsigned int size;
} dmap;
void *put(struct map *map, char *key, void *val);
struct map *map_init(unsigned int size);
void *get(struct map *map, char *key);
struct map *map_new();
#endif