htable: add a htable_prev method to oppose _next
[ccan] / ccan / htable / htable_type.h
index 15a70fc28d039e31f9285f83a496e14faa09c71f..ba33f139d72a89387c73847b80bab73f47e1ce15 100644 (file)
@@ -43,6 +43,7 @@
  * Iteration over hashtable is also supported:
  *     type *<name>_first(const struct <name> *ht, struct <name>_iter *i);
  *     type *<name>_next(const struct <name> *ht, struct <name>_iter *i);
+ *     type *<name>_prev(const struct <name> *ht, struct <name>_iter *i);
  *
  * It's currently safe to iterate over a changing hashtable, but you might
  * miss an element.  Iteration isn't very efficient, either.
                                        struct name##_iter *iter)       \
        {                                                               \
                return htable_next(&ht->raw, &iter->i);                 \
+       }                                                               \
+       static inline UNNEEDED type *name##_prev(const struct name *ht, \
+                                       struct name##_iter *iter)       \
+       {                                                               \
+               return htable_prev(&ht->raw, &iter->i);                 \
        }
 
 #if HAVE_TYPEOF