]> git.ozlabs.org Git - ccan/blobdiff - ccan/invbloom/invbloom.h
edit_distance: calculate edit distance between strings
[ccan] / ccan / invbloom / invbloom.h
index 6306d5b84e0b8eb3c82069d8268ccfb9845d082c..a1c83c77641d6416032383abf4af4609f2922b8a 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, bool, void *);
+       void *singleton_data;
 };
 
 /**
@@ -27,6 +30,32 @@ struct invbloom *invbloom_new_(const tal_t *ctx,
                               size_t id_size,
                               size_t n_elems, u32 salt);
 
+/**
+ * invbloom_singleton_cb - set callback for a singleton created/destroyed.
+ * @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.
+ *
+ * @cb is of form "void @cb(struct invbloom *ib, size_t bucket, bool
+ * before, data)".  @before is true if the call is done before the
+ * singleton in @bucket is removed (ie. ib->counts[bucket] is -1 or 1,
+ * but is about to change).  @before is false if the call is done
+ * after the operation, and the bucket is now a singleton.
+ */
+#define invbloom_singleton_cb(ib, cb, data)                    \
+       invbloom_singleton_cb_((ib),                            \
+              typesafe_cb_preargs(void, void *, (cb), (data),  \
+                                  struct invbloom *, size_t, bool), (data))
+
+void invbloom_singleton_cb_(struct invbloom *ib,
+                           void (*cb)(struct invbloom *,
+                                      size_t bucket, bool before, void *),
+                           void *data);
 
 /**
  * invbloom_insert - add a new element