diff options
| author | Franklin Wei <git@fwei.tk> | 2016-03-26 20:47:42 -0400 |
|---|---|---|
| committer | Franklin Wei <git@fwei.tk> | 2016-03-26 20:47:42 -0400 |
| commit | f6ced470369099e3d837e661b59f9dc539ebde70 (patch) | |
| tree | 19b10984b9670f21a421f61d11a29fb83b51db6f /src/hash.c | |
| parent | eb8b5907df2cf3c4b593197d40d10e83e6943ee3 (diff) | |
| download | netcosm-f6ced470369099e3d837e661b59f9dc539ebde70.zip netcosm-f6ced470369099e3d837e661b59f9dc539ebde70.tar.gz netcosm-f6ced470369099e3d837e661b59f9dc539ebde70.tar.bz2 netcosm-f6ced470369099e3d837e661b59f9dc539ebde70.tar.xz | |
fix drop bug
Diffstat (limited to 'src/hash.c')
| -rw-r--r-- | src/hash.c | 50 |
1 files changed, 50 insertions, 0 deletions
@@ -328,6 +328,56 @@ bool hash_remove(void *ptr, const void *key) return false; } +/* return an opaque pointer to a particular key/value pair */ +struct hash_export_node hash_get_internal_node(void *ptr, const void *key) +{ + if(ptr) + { + struct hash_map *map = ptr; + CHECK_SENTINEL(map); + unsigned hash = map->hash(key) % map->table_sz; + + struct hash_node *iter = map->table[hash], *last = NULL;; + + while(iter) + { + if(map->compare(key, iter->key) == 0) + { + struct hash_export_node ret; + ret.hash = hash; + ret.last = last; + ret.node = iter; + ret.next = iter->next; + return ret; + } + last = iter; + iter = iter->next; + } + /* fall through */ + } + + struct hash_export_node ret; + ret.node = NULL; + return ret; +} + +void hash_del_internal_node(void *ptr, const struct hash_export_node *node) +{ + if(ptr) + { + if(node->node) + { + struct hash_map *map = ptr; + CHECK_SENTINEL(map); + + if(node->last) + ((struct hash_node*)node->last)->next = node->next; + else + map->table[node->hash] = node->next; + } + } +} + void *hash_getkeyptr(void *ptr, const void *key) { if(ptr) |