]> git.ozlabs.org Git - ccan/blobdiff - ccan/htable/htable.h
htable: add a htable_prev method to oppose _next
[ccan] / ccan / htable / htable.h
index ed668e7405ed84e819cec49b85f8186b85287933..e150c2ef0958065d3e289482d78dfe8267017a9b 100644 (file)
@@ -51,6 +51,21 @@ struct htable {
 void htable_init(struct htable *ht,
                 size_t (*rehash)(const void *elem, void *priv), void *priv);
 
+/**
+ * htable_init_sized - initialize an empty hash table of given size.
+ * @ht: the hash table to initialize
+ * @rehash: hash function to use for rehashing.
+ * @priv: private argument to @rehash function.
+ * @size: the number of element.
+ *
+ * If this returns false, @ht is still usable, but may need to do reallocation
+ * upon an add.  If this returns true, it will not need to reallocate within
+ * @size htable_adds.
+ */
+bool htable_init_sized(struct htable *ht,
+                      size_t (*rehash)(const void *elem, void *priv),
+                      void *priv, size_t size);
+
 /**
  * htable_clear - empty a hash table.
  * @ht: the hash table to clear
@@ -163,6 +178,21 @@ void *htable_first(const struct htable *htable, struct htable_iter *i);
  */
 void *htable_next(const struct htable *htable, struct htable_iter *i);
 
+/**
+ * htable_prev - find the previous entry in the hash table
+ * @ht: the hashtable
+ * @i: the struct htable_iter to use
+ *
+ * Get previous entry in the hashtable; NULL if all done.
+ *
+ * "previous" here only means the item that would have been returned by
+ * htable_next() before the item it returned most recently.
+ *
+ * This is usually used in the middle of (or after) a htable_next iteration and
+ * to "unwind" actions taken.
+ */
+void *htable_prev(const struct htable *htable, struct htable_iter *i);
+
 /**
  * htable_delval - remove an iterated pointer from a hash table
  * @ht: the htable