-options to play with
[oweals/gnunet.git] / src / consensus / ibf.h
1 /*
2       This file is part of GNUnet
3       (C) 2012 Christian Grothoff (and other contributing authors)
4
5       GNUnet is free software; you can redistribute it and/or modify
6       it under the terms of the GNU General Public License as published
7       by the Free Software Foundation; either version 2, or (at your
8       option) any later version.
9
10       GNUnet is distributed in the hope that it will be useful, but
11       WITHOUT ANY WARRANTY; without even the implied warranty of
12       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13       General Public License for more details.
14
15       You should have received a copy of the GNU General Public License
16       along with GNUnet; see the file COPYING.  If not, write to the
17       Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18       Boston, MA 02111-1307, USA.
19  */
20
21
22 /**
23  * @file consensus/ibf.h
24  * @brief invertible bloom filter
25  * @author Florian Dold
26  */
27
28
29 /**
30  * Opaque handle to an invertible bloom filter (IBF).
31  *
32  * An IBF is a counting bloom filter that has the ability to restore
33  * the hashes of its stored elements with high probability.
34  */
35 struct InvertibleBloomFilter
36
37 /**
38  * Create an invertible bloom filter.
39  *
40  * @param size number of IBF buckets
41  * @param salt salt for mingling hashes, different salt may
42  *        result in less (or more) collisions
43  * @param hash_num number of buckets one element is hashed in
44  * @return the newly created invertible bloom filter
45  */
46 struct InvertibleBloomFilter *
47 ibf_create(int size, int salt, int hash_num);
48
49 /**
50  * Insert an element into an IBF.
51  *
52  * @param ibf the IBF
53  * @param id the element's hash code
54  */
55 void
56 ibf_insert (struct InvertibleBloomFilter *ibf, GNUNET_HashCode *id);
57
58 /**
59  * Subtract ibf2 from ibf1, storing the result in ibf1.
60  * The two IBF's must have the same parameters size and hash_num.
61  */
62 void
63 ibf_subtract (struct InvertibleBloomFilter *ibf1, struct InvertibleBloomFilter *ibf2);
64
65 /**
66  * Decode and remove an element from the IBF, if possible.
67  *
68  * @param ibf the invertible bloom filter
69  * @param the id of the element is written to this hash code
70  * @return GNUNET_YES if decoding an element was successful, GNUNET_NO if it failed to decode
71  */
72 int
73 ibf_decode (struct InvertibleBloomFilter *ibf, struct GNUNET_HashCode *ret_id);
74
75
76 /**
77  * Create a copy of an IBF, the copy has to be destroyed properly.
78  *
79  * @param ibf the IBF to copy
80  */
81 struct InvertibleBloomFilter *
82 ibf_dup (struct InvertibleBloomFilter *ibf);
83
84 /*
85 ibf_hton();
86
87 ibf_ntoh();
88 */
89
90 /**
91  * Destroy all resources associated with the invertible bloom filter.
92  * No more ibf_*-functions may be called on ibf after calling destroy.
93  *
94  * @param ibf the intertible bloom filter to destroy
95  */
96 void
97 ibf_destroy (struct InvertibleBloomFilter *ibf);
98