diff options
| author | Franklin Wei <git@fwei.tk> | 2016-02-12 21:54:42 -0500 |
|---|---|---|
| committer | Franklin Wei <git@fwei.tk> | 2016-02-16 20:42:49 -0500 |
| commit | b110e7e0c519cc9575f8d224f0f75aca0d73946f (patch) | |
| tree | c3f33326a5e4822f2251e8d7370294096ab2eba4 /src/hash.h | |
| parent | a006044fbcb3355f0fa063720e7c41f4971894a0 (diff) | |
| download | netcosm-b110e7e0c519cc9575f8d224f0f75aca0d73946f.zip netcosm-b110e7e0c519cc9575f8d224f0f75aca0d73946f.tar.gz netcosm-b110e7e0c519cc9575f8d224f0f75aca0d73946f.tar.bz2 netcosm-b110e7e0c519cc9575f8d224f0f75aca0d73946f.tar.xz | |
support multiple objects sharing the same name
Diffstat (limited to 'src/hash.h')
| -rw-r--r-- | src/hash.h | 18 |
1 files changed, 14 insertions, 4 deletions
@@ -16,17 +16,24 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#pragma once + #include <stdbool.h> #include <stddef.h> -#pragma once - /* simple, generic chained hash map implementation */ +/* no duplicate keys are allowed */ +/* O(n) insertion */ + +/* for telling containers apart */ +#define HASH_SENTINEL 0x10 +#define MULTIMAP_SENTINEL 0x11 unsigned hash_djb(const void*); int compare_strings(const void*, const void*); +int compare_strings_nocase(const void*, const void*); -void *hash_init(size_t tabsz, unsigned (*hash_fn)(const void*), +void *hash_init(size_t tabsz, unsigned (*hash_fn)(const void *key), int (*compare_key)(const void*, const void*)); void hash_setfreedata_cb(void*, void (*cb)(void *data)); @@ -47,6 +54,9 @@ void hash_free(void*); */ void *hash_insert(void*, const void *key, const void *data); +/* overwrite an existing key/value pair with a new one */ +void hash_overwrite(void*, const void *key, const void *data); + /* returns NULL if not found */ void *hash_lookup(void*, const void *key); @@ -83,7 +93,7 @@ void *hash_getkeyptr(void*, const void *key); #define SIMP_EQUAL(TYPE, NAME) \ int NAME (const void *a, const void *b) \ { \ - return !(*((const TYPE*)a) == *((const TYPE*)b)); \ + return memcmp((a), (b), sizeof(TYPE)); \ } size_t hash_size(void*); |