1 /* Copyright (c) 2003-2004, Roger Dingledine
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2021, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
6 #ifndef TOR_BLOOMFILT_H
7 #define TOR_BLOOMFILT_H
12 * \brief Header for bloomfilt.c
16 #include "lib/cc/torint.h"
17 #include "lib/container/bitarray.h"
19 /** A set of elements, implemented as a Bloom filter. */
20 typedef struct bloomfilt_t bloomfilt_t
;
22 /** How many 64-bit siphash values to extract per item. */
23 #define BLOOMFILT_N_HASHES 2
25 /** How much key material do we need to randomize hashes? */
26 #define BLOOMFILT_KEY_LEN (BLOOMFILT_N_HASHES * 16)
29 typedef uint64_t (*bloomfilt_hash_fn
)(const struct sipkey
*key
,
32 void bloomfilt_add(bloomfilt_t
*set
, const void *item
);
33 int bloomfilt_probably_contains(const bloomfilt_t
*set
, const void *item
);
35 bloomfilt_t
*bloomfilt_new(int max_elements
,
36 bloomfilt_hash_fn hashfn
,
37 const uint8_t *random_key
);
38 void bloomfilt_free_(bloomfilt_t
* set
);
39 #define bloomfilt_free(set) FREE_AND_NULL(bloomfilt_t, bloomfilt_free_, (set))
41 #endif /* !defined(TOR_BLOOMFILT_H) */