10 * htable_new - allocate a hash tree.
11 * @rehash: hash function to use for rehashing.
12 * @priv: private argument to @rehash function.
14 struct htable *htable_new(size_t (*hash)(const void *elem, void *priv),
18 * htable_free - dellocate a hash tree.
20 * This doesn't do anything to any pointers left in it.
22 void htable_free(const struct htable *);
25 * htable_rehash - use a hashtree's rehash function
26 * @elem: the argument to rehash()
29 size_t htable_rehash(const void *elem);
32 * htable_add - add a pointer into a hash tree.
34 * @hash: the hash value of the object
35 * @p: the non-NULL pointer
37 * Also note that this can only fail due to allocation failure. Otherwise, it
40 bool htable_add(struct htable *ht, size_t hash, const void *p);
43 * htable_del - remove a pointer from a hash tree
45 * @hash: the hash value of the object
48 * Returns true if the pointer was found (and deleted).
50 bool htable_del(struct htable *ht, size_t hash, const void *p);
53 * struct htable_iter - iterator or htable_first or htable_firstval etc.
55 * This refers to a location inside the hashtable.
62 * htable_firstval - find a candidate for a given hash value
63 * @htable: the hashtable
64 * @i: the struct htable_iter to initialize
65 * @hash: the hash value
67 * You'll need to check the value is what you want; returns NULL if none.
71 void *htable_firstval(const struct htable *htable,
72 struct htable_iter *i, size_t hash);
75 * htable_nextval - find another candidate for a given hash value
76 * @htable: the hashtable
77 * @i: the struct htable_iter to initialize
78 * @hash: the hash value
80 * You'll need to check the value is what you want; returns NULL if no more.
82 void *htable_nextval(const struct htable *htable,
83 struct htable_iter *i, size_t hash);
86 * htable_get - find an entry in the hash table
88 * @h: the hash value of the entry
89 * @cmp: the comparison function
90 * @ptr: the pointer to hand to the comparison function.
92 * Convenient inline wrapper for htable_firstval/htable_nextval loop.
94 static inline void *htable_get(const struct htable *ht,
96 bool (*cmp)(const void *candidate, void *ptr),
102 for (c = htable_firstval(ht,&i,h); c; c = htable_nextval(ht,&i,h)) {
103 if (cmp(c, (void *)ptr))
110 * htable_first - find an entry in the hash table
112 * @i: the struct htable_iter to initialize
114 * Get an entry in the hashtable; NULL if empty.
116 void *htable_first(const struct htable *htable, struct htable_iter *i);
119 * htable_next - find another entry in the hash table
121 * @i: the struct htable_iter to use
123 * Get another entry in the hashtable; NULL if all done.
124 * This is usually used after htable_first or prior non-NULL htable_next.
126 void *htable_next(const struct htable *htable, struct htable_iter *i);
129 * htable_delval - remove an iterated pointer from a hash tree
131 * @i: the htable_iter
133 * Usually used to delete a hash entry after it has been found with
134 * htable_firstval etc.
136 void htable_delval(struct htable *ht, struct htable_iter *i);
138 #endif /* CCAN_HTABLE_H */