1 /* dict.h - Abstract dictionary type
2 * Copyright 2000-2004 srvx Development Team
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version. Important limitations are
8 * listed in the COPYING file that accompanies this software.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, email srvx-maintainers@srvx.net.
23 typedef void (*free_f)(void*);
24 typedef int (*dict_iterator_f)(const char *key, void *data, void *extra);
26 /* exposed ONLY for the iteration macros; if you use these, DIE */
30 struct dict_node *l, *r, *prev, *next;
34 free_f free_keys, free_data;
35 struct dict_node *root, *first, *last;
40 typedef struct dict *dict_t;
41 typedef struct dict_node *dict_iterator_t;
43 #define dict_first(DICT) ((DICT) ? (DICT)->first : NULL)
44 #define iter_key(ITER) ((ITER)->key)
45 #define iter_data(ITER) ((ITER)->data)
46 #define iter_next(ITER) ((ITER)->next)
48 dict_t dict_new(void);
49 /* dict_foreach returns key of node causing halt (non-zero return from
50 * iterator function) */
51 const char* dict_foreach(dict_t dict, dict_iterator_f it, void *extra);
52 void dict_insert(dict_t dict, const char *key, void *data);
53 void dict_set_free_keys(dict_t dict, free_f free_keys);
54 void dict_set_free_data(dict_t dict, free_f free_data);
55 unsigned int dict_size(dict_t dict);
56 /* if present!=NULL, then *present=1 iff node was found (if node is
57 * not found, return value is NULL, which may be a valid datum) */
58 void* dict_find(dict_t dict, const char *key, int *present);
59 int dict_remove2(dict_t dict, const char *key, int no_dispose);
60 #define dict_remove(DICT, KEY) dict_remove2(DICT, KEY, 0)
61 char *dict_sanity_check(dict_t dict);
62 void dict_delete(dict_t dict);
64 #endif /* !defined(DICT_H) */