1 #ifndef CCAN_HASHTABLE_H
2 #define CCAN_HASHTABLE_H
9 * hashtable_new - allocate a hash tree.
10 * @rehash: hash function to use for rehashing.
11 * @priv: private argument to @rehash function.
13 struct hashtable *hashtable_new(unsigned long (*rehash)(const void *elem,
18 * hashtable_free - dellocate a hash tree.
20 * This doesn't do anything to any pointers left in it.
22 void hashtable_free(struct hashtable *);
25 * hashtable_find - look for an object in a hash tree.
27 * @hash: the hash value of the object you are seeking
28 * @cmp: a comparison function: returns true if the object is found
29 * @cmpdata: the data to hand as second arg to @cmp
31 * Note that you can do all the work inside the cmp function if you want to:
32 * hashtable_find will return @htelem if @cmp returns true.
34 void *hashtable_find(struct hashtable *ht,
36 bool (*cmp)(const void *htelem, void *cmpdata),
40 * hashtable_add - add an (aligned) pointer into a hash tree.
42 * @hash: the hash value of the object
43 * @p: the non-NULL pointer, usually from malloc or equiv.
45 * Note that this implementation (ab)uses the lower bits of the pointer, so
46 * it will abort if the pointer is not aligned to 8 bytes.
48 * Also note that this can only fail due to allocation failure. Otherwise, it
51 bool hashtable_add(struct hashtable *ht, unsigned long hash, const void *p);
54 * hashtable_del - remove a pointer from a hash tree
56 * @hash: the hash value of the object
59 * Returns true if the pointer was found (and deleted).
61 bool hashtable_del(struct hashtable *ht, unsigned long hash, const void *p);
64 * hashtable_traverse - call a function on every pointer in hash tree
66 * @cb: the callback: returns true to abort traversal.
67 * @cbarg: the argument to the callback
69 * Note that your traversal callback may delete any entry (it won't crash),
70 * but it may make the traverse unreliable.
72 void hashtable_traverse(struct hashtable *ht, bool (*cb)(void *p, void *cbarg),
74 #endif /* CCAN_HASHTABLE_H */