Re: [PATCH v4 3/6] bloom: add helper to check if any key in a vector is present
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Sep 10, 2026, 07:03 UTC
- Message-ID
- <aqJWX0INerT8F687@pks.im>
- In-Reply-To
- <20260901-toon-speed-up-last-modified-v4-3-a09949800404@iotcl.com>
On Tue, Sep 01, 2026 at 11:10:23AM +0200, Toon Claes wrote:
Show 19 quoted lines
> diff --git a/bloom.c b/bloom.c
> index caf22f9831..b96534e6e3 100644
> --- a/bloom.c
> +++ b/bloom.c
> @@ -607,6 +607,18 @@ int bloom_filter_contains_vec(const struct bloom_filter *filter,
> return ret;
> }
>
> +int bloom_filter_contains_any_vec(const struct bloom_filter *filter,
> + const struct bloom_keyvec *vec,
> + const struct bloom_filter_settings *settings)
> +{
> + int ret = 0;
> +
> + for (size_t nr = 0; !ret && nr < vec->count; nr++)
> + ret = bloom_filter_contains(filter, &vec->key[nr], settings);
> +
> + return ret;
> +}`bloom_filter_contains()` may also return -1 in case `filter->len == 0`, and we'd bubble up that code. But here...
Show 18 quoted lines
> diff --git a/bloom.h b/bloom.h > index 92ab2100d3..f508db23ad 100644 > --- a/bloom.h > +++ b/bloom.h > @@ -164,6 +164,17 @@ int bloom_filter_contains_vec(const struct bloom_filter *filter, > const struct bloom_keyvec *v, > const struct bloom_filter_settings *settings); > > +/* > + * bloom_filter_contains_any_vec - Check if any key in a key vector is in the > + * Bloom filter. > + * > + * Returns 1 if **any** key in the vector is present in the filter, 0 if none > + * of them are. > + */ > +int bloom_filter_contains_any_vec(const struct bloom_filter *filter, > + const struct bloom_keyvec *v, > + const struct bloom_filter_settings *settings);
... you only document that it may return 0 or 1. We should either properly document this or munge the returned value to be 0 or 1, only. And if so, we could probably adapt this function to have a boolean return value.
Patrick