diff options
| author | Franklin Wei <git@fwei.tk> | 2015-12-25 14:25:16 -0500 |
|---|---|---|
| committer | Franklin Wei <git@fwei.tk> | 2015-12-25 14:25:16 -0500 |
| commit | 2a81620aa5b740d7f77aff8177a983b7492b8ea0 (patch) | |
| tree | 98c132a338ec9aebfc43b365ea31974463f19703 /src/hash.h | |
| parent | 53c15b0461ee39a4c32e61ff484389efb1e91d84 (diff) | |
| download | netcosm-2a81620aa5b740d7f77aff8177a983b7492b8ea0.zip netcosm-2a81620aa5b740d7f77aff8177a983b7492b8ea0.tar.gz netcosm-2a81620aa5b740d7f77aff8177a983b7492b8ea0.tar.bz2 netcosm-2a81620aa5b740d7f77aff8177a983b7492b8ea0.tar.xz | |
tons of stuff
Diffstat (limited to 'src/hash.h')
| -rw-r--r-- | src/hash.h | 26 |
1 files changed, 23 insertions, 3 deletions
@@ -1,9 +1,9 @@ #include <stddef.h> -#include <stdlib.h> -/* simple, generic hash map implementation */ +/* simple, generic chained hash map implementation */ -unsigned hash_djb(const char*); +unsigned hash_djb(const void*); +int compare_strings(const void*, const void*); void *hash_init(size_t tabsz, unsigned (*hash_fn)(const void*), int (*compare_key)(const void*, const void*)); @@ -16,3 +16,23 @@ void *hash_insert(void*, const void *key, const void *data); /* returns NULL if not found */ void *hash_lookup(void*, const void *key); + +struct hash_pair { + void *key; + unsigned char value[0]; +}; + +/* insert n key->pair members of size pairsize */ +void hash_insert_pairs(void*, const struct hash_pair*, size_t pairsize, size_t n); + +#define SIMP_HASH(TYPE, NAME) \ + unsigned NAME (const void *key) \ + { \ + return *((TYPE*)key); \ + } + +#define SIMP_EQUAL(TYPE, NAME) \ + int NAME (const void *a, const void *b) \ + { \ + return !(*((TYPE*)a) == *((TYPE*)b)); \ + } |