]> git.ozlabs.org Git - ccan/blobdiff - ccan/invbloom/invbloom.h
invbloom: add callback for when an element becomes a singleton.
[ccan] / ccan / invbloom / invbloom.h
index 6306d5b84e0b8eb3c82069d8268ccfb9845d082c..d30223d2fe3e4d6f53e92c26217e3c47123bc114 100644 (file)
@@ -2,6 +2,7 @@
 #ifndef CCAN_INVBLOOM_H
 #define CCAN_INVBLOOM_H
 #include <ccan/short_types/short_types.h>
+#include <ccan/typesafe_cb/typesafe_cb.h>
 #include <ccan/tal/tal.h>
 
 struct invbloom {
@@ -10,6 +11,8 @@ struct invbloom {
        u32 salt;
        s32 *count; /* [n_elems] */
        u8 *idsum; /* [n_elems][id_size] */
+       void (*singleton)(struct invbloom *ib, size_t elem, void *);
+       void *singleton_data;
 };
 
 /**
@@ -27,6 +30,26 @@ struct invbloom *invbloom_new_(const tal_t *ctx,
                               size_t id_size,
                               size_t n_elems, u32 salt);
 
+/**
+ * invbloom_singleton_cb - set callback for when a singleton is found.
+ * @ib: the invertable bloom lookup table.
+ * @cb: the function to call (or NULL for none)
+ * @data: the data to hand to the function.
+ *
+ * This may be called by any function which mutates the table,
+ * possibly multiple times for a single call.  The particular
+ * @ib bucket will be consistent, but the rest of the table may
+ * not be.
+ */
+#define invbloom_singleton_cb(ib, cb, data)                    \
+       invbloom_singleton_cb_((ib),                            \
+              typesafe_cb_preargs(void, void *, (cb), (data),  \
+                                  struct invbloom *, size_t), (data))
+
+void invbloom_singleton_cb_(struct invbloom *ib,
+                           void (*cb)(struct invbloom *,
+                                      size_t bucket, void *),
+                           void *data);
 
 /**
  * invbloom_insert - add a new element