-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdict.h
34 lines (21 loc) · 870 Bytes
/
dict.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
/* A data type and functions for a mapping */
typedef struct dict dict;
typedef struct dict_iterator dict_iterator;
// Parametrization of the dict
typedef struct word * dict_key;
typedef int dict_value;
// dict API
// NULL on failure
dict *dict_alloc(void);
void dict_free(dict *);
// 0 = success, -1 = fail
// after the call, key is owned by the dict; the caller should no longer use it
int dict_set(dict *d, dict_key key, dict_value value);
// 1 = found, 0 = not found, -1 = fail
int dict_get(dict *d, dict_key key, dict_value *result);
// NULL on failure
dict_iterator *dict_iterator_new(dict *d);
void dict_iterator_free(dict_iterator *it);
// 1 = found, 0 = at end (output set to NULL), -1 = fail
// The dict owns the resulting key; it is valid until the next dict operation (except dict_get).
int dict_iterator_next(dict_iterator *it, dict_key *key);