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.c | |
| 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.c')
| -rw-r--r-- | src/hash.c | 23 |
1 files changed, 22 insertions, 1 deletions
@@ -1,4 +1,6 @@ #include "hash.h" +#include <stdlib.h> +#include <string.h> struct hash_node { const void *key; @@ -13,8 +15,9 @@ struct hash_map { size_t table_sz; }; -unsigned hash_djb(const char *str) +unsigned hash_djb(const void *ptr) { + const char *str = ptr; unsigned hash = 5381; char c; while((c = *str++)) @@ -25,6 +28,12 @@ unsigned hash_djb(const char *str) return hash; } +/* wrapper to supress warnings */ +int compare_strings(const void *a, const void *b) +{ + return strcmp(a,b); +} + void *hash_init(size_t sz, unsigned (*hash_fn)(const void*), int (*compare_keys)(const void*, const void*)) { @@ -98,3 +107,15 @@ void *hash_lookup(void *ptr, const void *key) } return NULL; } + +void hash_insert_pairs(void *ptr, const struct hash_pair *pairs, + size_t pairsize, size_t n) +{ + const char *iter = (const char*)pairs; + for(unsigned i = 0; i < n; ++i) + { + const struct hash_pair *pair = (const struct hash_pair*)iter; + hash_insert(ptr, pair->key, pair); + iter += pairsize; + } +} |