aboutsummaryrefslogtreecommitdiff
path: root/src/hash.c
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2016-03-26 20:47:42 -0400
committerFranklin Wei <git@fwei.tk>2016-03-26 20:47:42 -0400
commitf6ced470369099e3d837e661b59f9dc539ebde70 (patch)
tree19b10984b9670f21a421f61d11a29fb83b51db6f /src/hash.c
parenteb8b5907df2cf3c4b593197d40d10e83e6943ee3 (diff)
downloadnetcosm-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.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/hash.c b/src/hash.c
index 59c05bf..290c668 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -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)