X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Finvbloom%2Finvbloom.h;h=a1c83c77641d6416032383abf4af4609f2922b8a;hb=ee77e470b467cf85dc533cee8c08e08bd4c9be06;hp=6306d5b84e0b8eb3c82069d8268ccfb9845d082c;hpb=ea3e48a4a25b87f23ea76e7a76f7a205fca73ce6;p=ccan diff --git a/ccan/invbloom/invbloom.h b/ccan/invbloom/invbloom.h index 6306d5b8..a1c83c77 100644 --- a/ccan/invbloom/invbloom.h +++ b/ccan/invbloom/invbloom.h @@ -2,6 +2,7 @@ #ifndef CCAN_INVBLOOM_H #define CCAN_INVBLOOM_H #include +#include #include 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