2 This file is part of GNUnet
3 Copyright (C) 2012 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @file set/gnunet-service-set_union_strata_estimator.h
21 * @brief estimator of set difference
22 * @author Florian Dold
25 #ifndef GNUNET_CONSENSUS_STRATA_ESTIMATOR_H
26 #define GNUNET_CONSENSUS_STRATA_ESTIMATOR_H
29 #include "gnunet_common.h"
30 #include "gnunet_util_lib.h"
35 #if 0 /* keep Emacsens' auto-indent happy */
42 * A handle to a strata estimator.
44 struct StrataEstimator
47 * The IBFs of this strata estimator.
49 struct InvertibleBloomFilter **strata;
52 * Size of the IBF array in @e strata
54 unsigned int strata_count;
57 * Size of each IBF stratum (in bytes)
59 unsigned int ibf_size;
64 * Write the given strata estimator to the buffer.
66 * @param se strata estimator to serialize
67 * @param[out] buf buffer to write to, must be of appropriate size
68 * @return number of bytes written to @a buf
71 strata_estimator_write (const struct StrataEstimator *se,
76 * Read strata from the buffer into the given strata
77 * estimator. The strata estimator must already be allocated.
79 * @param buf buffer to read from
80 * @param buf_len number of bytes in @a buf
81 * @param is_compressed is the data compressed?
82 * @param[out] se strata estimator to write to
83 * @return #GNUNET_OK on success
86 strata_estimator_read (const void *buf,
89 struct StrataEstimator *se);
93 * Create a new strata estimator with the given parameters.
95 * @param strata_count number of stratas, that is, number of ibfs in the estimator
96 * @param ibf_size size of each ibf stratum
97 * @param ibf_hashnum hashnum parameter of each ibf
98 * @return a freshly allocated, empty strata estimator, NULL on error
100 struct StrataEstimator *
101 strata_estimator_create (unsigned int strata_count,
103 uint8_t ibf_hashnum);
107 * Get an estimation of the symmetric difference of the elements
108 * contained in both strata estimators.
110 * @param se1 first strata estimator
111 * @param se2 second strata estimator
112 * @return abs(|se1| - |se2|)
115 strata_estimator_difference (const struct StrataEstimator *se1,
116 const struct StrataEstimator *se2);
120 * Add a key to the strata estimator.
122 * @param se strata estimator to add the key to
123 * @param key key to add
126 strata_estimator_insert (struct StrataEstimator *se,
131 * Remove a key from the strata estimator.
133 * @param se strata estimator to remove the key from
134 * @param key key to remove
137 strata_estimator_remove (struct StrataEstimator *se,
142 * Destroy a strata estimator, free all of its resources.
144 * @param se strata estimator to destroy.
147 strata_estimator_destroy (struct StrataEstimator *se);
151 * Make a copy of a strata estimator.
153 * @param se the strata estimator to copy
156 struct StrataEstimator *
157 strata_estimator_dup (struct StrataEstimator *se);
160 #if 0 /* keep Emacsens' auto-indent happy */