2 This file is part of GNUnet
3 (C) 2012 Christian Grothoff (and other contributing authors)
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.
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.
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.
23 * @file consensus/ibf.h
24 * @brief invertible bloom filter
25 * @author Florian Dold
30 * Opaque handle to an invertible bloom filter (IBF).
32 * An IBF is a counting bloom filter that has the ability to restore
33 * the hashes of its stored elements with high probability.
35 struct InvertibleBloomFilter
38 * Create an invertible bloom filter.
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
46 struct InvertibleBloomFilter *
47 ibf_create(int size, int salt, int hash_num);
50 * Insert an element into an IBF.
53 * @param id the element's hash code
56 ibf_insert (struct InvertibleBloomFilter *ibf, GNUNET_HashCode *id);
59 * Subtract ibf2 from ibf1, storing the result in ibf1.
60 * The two IBF's must have the same parameters size and hash_num.
63 ibf_subtract (struct InvertibleBloomFilter *ibf1, struct InvertibleBloomFilter *ibf2);
66 * Decode and remove an element from the IBF, if possible.
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
73 ibf_decode (struct InvertibleBloomFilter *ibf, struct GNUNET_HashCode *ret_id);
77 * Create a copy of an IBF, the copy has to be destroyed properly.
79 * @param ibf the IBF to copy
81 struct InvertibleBloomFilter *
82 ibf_dup (struct InvertibleBloomFilter *ibf);
91 * Destroy all resources associated with the invertible bloom filter.
92 * No more ibf_*-functions may be called on ibf after calling destroy.
94 * @param ibf the intertible bloom filter to destroy
97 ibf_destroy (struct InvertibleBloomFilter *ibf);