Tor  0.4.7.0-alpha-dev
bloomfilt.h
Go to the documentation of this file.
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 */
5 
6 #ifndef TOR_BLOOMFILT_H
7 #define TOR_BLOOMFILT_H
8 
9 /**
10  * \file bloomfilt.h
11  *
12  * \brief Header for bloomfilt.c
13  **/
14 
15 #include "orconfig.h"
16 #include "lib/cc/torint.h"
17 #include "lib/container/bitarray.h"
18 
19 /** A set of elements, implemented as a Bloom filter. */
20 typedef struct bloomfilt_t bloomfilt_t;
21 
22 /** How many 64-bit siphash values to extract per item. */
23 #define BLOOMFILT_N_HASHES 2
24 
25 /** How much key material do we need to randomize hashes? */
26 #define BLOOMFILT_KEY_LEN (BLOOMFILT_N_HASHES * 16)
27 
28 struct sipkey;
29 typedef uint64_t (*bloomfilt_hash_fn)(const struct sipkey *key,
30  const void *item);
31 
32 void bloomfilt_add(bloomfilt_t *set, const void *item);
33 int bloomfilt_probably_contains(const bloomfilt_t *set, const void *item);
34 
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))
40 
41 #endif /* !defined(TOR_BLOOMFILT_H) */
Implements a variable-sized (but non-resizeable) bit-array.
void bloomfilt_add(bloomfilt_t *set, const void *item)
Definition: bloomfilt.c:38
int bloomfilt_probably_contains(const bloomfilt_t *set, const void *item)
Definition: bloomfilt.c:54
bloomfilt_t * bloomfilt_new(int max_elements, bloomfilt_hash_fn hashfn, const uint8_t *random_key)
Definition: bloomfilt.c:78
void bloomfilt_free_(bloomfilt_t *set)
Definition: bloomfilt.c:107
Definition: siphash.h:6
Integer definitions used throughout Tor.