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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file set/gnunet-service-set_union_strata_estimator.h
23 * @brief estimator of set difference
24 * @author Florian Dold
27 #ifndef GNUNET_CONSENSUS_STRATA_ESTIMATOR_H
28 #define GNUNET_CONSENSUS_STRATA_ESTIMATOR_H
31 #include "gnunet_common.h"
32 #include "gnunet_util_lib.h"
37 #if 0 /* keep Emacsens' auto-indent happy */
44 * A handle to a strata estimator.
46 struct StrataEstimator {
48 * The IBFs of this strata estimator.
50 struct InvertibleBloomFilter **strata;
53 * Size of the IBF array in @e strata
55 unsigned int strata_count;
58 * Size of each IBF stratum (in bytes)
60 unsigned int ibf_size;
65 * Write the given strata estimator to the buffer.
67 * @param se strata estimator to serialize
68 * @param[out] buf buffer to write to, must be of appropriate size
69 * @return number of bytes written to @a buf
72 strata_estimator_write(const struct StrataEstimator *se,
77 * Read strata from the buffer into the given strata
78 * estimator. The strata estimator must already be allocated.
80 * @param buf buffer to read from
81 * @param buf_len number of bytes in @a buf
82 * @param is_compressed is the data compressed?
83 * @param[out] se strata estimator to write to
84 * @return #GNUNET_OK on success
87 strata_estimator_read(const void *buf,
90 struct StrataEstimator *se);
94 * Create a new strata estimator with the given parameters.
96 * @param strata_count number of stratas, that is, number of ibfs in the estimator
97 * @param ibf_size size of each ibf stratum
98 * @param ibf_hashnum hashnum parameter of each ibf
99 * @return a freshly allocated, empty strata estimator, NULL on error
101 struct StrataEstimator *
102 strata_estimator_create(unsigned int strata_count,
104 uint8_t ibf_hashnum);
108 * Get an estimation of the symmetric difference of the elements
109 * contained in both strata estimators.
111 * @param se1 first strata estimator
112 * @param se2 second strata estimator
113 * @return abs(|se1| - |se2|)
116 strata_estimator_difference(const struct StrataEstimator *se1,
117 const struct StrataEstimator *se2);
121 * Add a key to the strata estimator.
123 * @param se strata estimator to add the key to
124 * @param key key to add
127 strata_estimator_insert(struct StrataEstimator *se,
132 * Remove a key from the strata estimator.
134 * @param se strata estimator to remove the key from
135 * @param key key to remove
138 strata_estimator_remove(struct StrataEstimator *se,
143 * Destroy a strata estimator, free all of its resources.
145 * @param se strata estimator to destroy.
148 strata_estimator_destroy(struct StrataEstimator *se);
152 * Make a copy of a strata estimator.
154 * @param se the strata estimator to copy
157 struct StrataEstimator *
158 strata_estimator_dup(struct StrataEstimator *se);
161 #if 0 /* keep Emacsens' auto-indent happy */