]> git.ozlabs.org Git - ccan/blobdiff - ccan/htable/htable.c
htable: add a htable_prev method to oppose _next
[ccan] / ccan / htable / htable.c
index 59048dc0ada0df95b23583e0dfbba65d3c96768c..5a773cd8876d2f36b53733c659757213811651ff 100644 (file)
@@ -135,6 +135,17 @@ void *htable_next(const struct htable *ht, struct htable_iter *i)
        return NULL;
 }
 
+void *htable_prev(const struct htable *ht, struct htable_iter *i)
+{
+       for (;;) {
+               if (!i->off)
+                       return NULL;
+               i->off --;
+               if (entry_is_valid(ht->table[i->off]))
+                       return get_raw_ptr(ht, ht->table[i->off]);
+       }
+}
+
 /* This does not expand the hash table, that's up to caller. */
 static void ht_add(struct htable *ht, const void *new, size_t h)
 {