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.
22 * @file consensus/ibf.h
23 * @brief invertible bloom filter
24 * @author Florian Dold
27 #ifndef GNUNET_CONSENSUS_IBF_H
28 #define GNUNET_CONSENSUS_IBF_H
31 #include "gnunet_common.h"
32 #include "gnunet_util_lib.h"
37 #if 0 /* keep Emacsens' auto-indent happy */
44 * Opaque handle to an invertible bloom filter (IBF).
46 * An IBF is a counting bloom filter that has the ability to restore
47 * the hashes of its stored elements with high probability.
49 struct InvertibleBloomFilter;
53 * Create an invertible bloom filter.
55 * @param size number of IBF buckets
56 * @param hash_num number of buckets one element is hashed in
57 * @param salt salt for mingling hashes, different salt may
58 * result in less (or more) collisions
59 * @return the newly created invertible bloom filter
61 struct InvertibleBloomFilter *
62 ibf_create(unsigned int size, unsigned int hash_num, uint32_t salt);
66 * Insert an element into an IBF.
69 * @param id the element's hash code
72 ibf_insert (struct InvertibleBloomFilter *ibf, const struct GNUNET_HashCode *id);
76 * Subtract ibf2 from ibf1, storing the result in ibf1.
77 * The two IBF's must have the same parameters size and hash_num.
80 ibf_subtract (struct InvertibleBloomFilter *ibf1, struct InvertibleBloomFilter *ibf2);
84 * Decode and remove an element from the IBF, if possible.
86 * @param ibf the invertible bloom filter to decode
87 * @param ret_id the hash code of the decoded element, if successful
88 * @param side sign of the cell's count where the decoded element came from.
89 * A negative sign indicates that the element was recovered resides in an IBF
90 * that was previously subtracted from.
91 * @return GNUNET_YES if decoding an element was successful, GNUNET_NO if the IBF is empty,
92 * GNUNET_SYSERR if the decoding has faile
95 ibf_decode (struct InvertibleBloomFilter *ibf, int *side, struct GNUNET_HashCode *ret_id);
99 * Create a copy of an IBF, the copy has to be destroyed properly.
101 * @param ibf the IBF to copy
103 struct InvertibleBloomFilter *
104 ibf_dup (struct InvertibleBloomFilter *ibf);
116 * Destroy all resources associated with the invertible bloom filter.
117 * No more ibf_*-functions may be called on ibf after calling destroy.
119 * @param ibf the intertible bloom filter to destroy
122 ibf_destroy (struct InvertibleBloomFilter *ibf);
125 #if 0 /* keep Emacsens' auto-indent happy */