1 /* Copyright (c) 2006-2014 Jonas Fonseca <jonas.fonseca@gmail.com>
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License as
5 * published by the Free Software Foundation; either version 2 of
6 * the License, or (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
23 typedef unsigned int string_map_key_t
;
24 typedef string_map_key_t (*string_map_hash_fn
)(const void *value
);
25 typedef const char *(*string_map_key_fn
)(const void *value
);
26 typedef bool (*string_map_iterator_fn
)(void *data
, void *value
);
29 string_map_hash_fn hash_fn
;
30 string_map_key_fn key_fn
;
36 extern string_map_hash_fn string_map_hash_helper
;
37 void *string_map_get(struct string_map
*map
, const char *key
);
38 void *string_map_put(struct string_map
*map
, const char *key
, void *value
);
39 void **string_map_put_to(struct string_map
*map
, const char *key
);
40 void *string_map_remove(struct string_map
*map
, void **slot
);
41 void string_map_clear(struct string_map
*map
);
42 void string_map_foreach(struct string_map
*map
, string_map_iterator_fn iterator
, void *data
);
44 #define DEFINE_STRING_MAP(name, type, key_member, init_size) \
46 name ## _key(const void *value) \
48 return ((type) value)->key_member; \
50 static string_map_key_t \
51 name ## _hash(const void *value) \
53 return string_map_hash_helper(name ## _key(value)); \
55 static struct string_map name = { \
62 /* vim: set ts=8 sw=8 noexpandtab: */