aboutsummaryrefslogtreecommitdiff
path: root/src/service/setu/gnunet-service-setu_strata_estimator.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/setu/gnunet-service-setu_strata_estimator.h')
-rw-r--r--src/service/setu/gnunet-service-setu_strata_estimator.h199
1 files changed, 199 insertions, 0 deletions
diff --git a/src/service/setu/gnunet-service-setu_strata_estimator.h b/src/service/setu/gnunet-service-setu_strata_estimator.h
new file mode 100644
index 000000000..4871a7fcd
--- /dev/null
+++ b/src/service/setu/gnunet-service-setu_strata_estimator.h
@@ -0,0 +1,199 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2012 GNUnet e.V.
4
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.
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 Affero General Public License for more details.
14
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/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file set/gnunet-service-setu_strata_estimator.h
23 * @brief estimator of set difference
24 * @author Florian Dold
25 * @author Elias Summermatter
26 */
27
28#ifndef GNUNET_SERVICE_SETU_STRATA_ESTIMATOR_H
29#define GNUNET_SERVICE_SETU_STRATA_ESTIMATOR_H
30
31#include "platform.h"
32#include "gnunet_common.h"
33#include "gnunet_util_lib.h"
34
35#ifdef __cplusplus
36extern "C"
37{
38#if 0 /* keep Emacsens' auto-indent happy */
39}
40#endif
41#endif
42
43
44/**
45 * A handle to a strata estimator.
46 */
47struct StrataEstimator
48{
49 /**
50 * The IBFs of this strata estimator.
51 */
52 struct InvertibleBloomFilter **strata;
53
54 /**
55 * Size of the IBF array in @e strata
56 */
57 unsigned int strata_count;
58
59 /**
60 * Size of each IBF stratum (in bytes)
61 */
62 unsigned int ibf_size;
63};
64
65struct MultiStrataEstimator
66{
67 /**
68 * Array of strata estimators
69 */
70 struct StrataEstimator **stratas;
71
72 /**
73 * Number of strata estimators in struct
74 */
75 uint8_t size;
76
77};
78
79/**
80 * Deteminate how many strata estimators in the message are necessary
81 * @param avg_element_size
82 * @param element_count
83 * @return number of strata's
84 */
85
86uint8_t
87determine_strata_count (uint64_t avg_element_size,
88 uint64_t element_count);
89
90
91/**
92 * Write the given strata estimator to the buffer.
93 *
94 * @param se strata estimator to serialize
95 * @param[out] buf buffer to write to, must be of appropriate size
96 * @return number of bytes written to @a buf
97 */
98size_t
99strata_estimator_write (struct MultiStrataEstimator *se,
100 uint16_t se_ibf_total_size,
101 uint8_t number_se_send,
102 void *buf);
103
104
105/**
106 * Read strata from the buffer into the given strata
107 * estimator. The strata estimator must already be allocated.
108 *
109 * @param buf buffer to read from
110 * @param buf_len number of bytes in @a buf
111 * @param is_compressed is the data compressed?
112 * @param[out] se strata estimator to write to
113 * @return #GNUNET_OK on success
114 */
115int
116strata_estimator_read (const void *buf,
117 size_t buf_len,
118 int is_compressed,
119 uint8_t number_se_received,
120 uint16_t se_ibf_total_size,
121 struct MultiStrataEstimator *se);
122
123
124/**
125 * Create a new strata estimator with the given parameters.
126 *
127 * @param strata_count number of stratas, that is, number of ibfs in the estimator
128 * @param ibf_size size of each ibf stratum
129 * @param ibf_hashnum hashnum parameter of each ibf
130 * @return a freshly allocated, empty strata estimator, NULL on error
131 */
132struct MultiStrataEstimator *
133strata_estimator_create (unsigned int strata_count,
134 uint32_t ibf_size,
135 uint8_t ibf_hashnum);
136
137
138/**
139 * Get an estimation of the symmetric difference of the elements
140 * contained in both strata estimators.
141 *
142 * @param se1 first strata estimator
143 * @param se2 second strata estimator
144 * @return nothing
145 */
146void
147strata_estimator_difference (const struct MultiStrataEstimator *se1,
148 const struct MultiStrataEstimator *se2);
149
150
151/**
152 * Add a key to the strata estimator.
153 *
154 * @param se strata estimator to add the key to
155 * @param key key to add
156 */
157void
158strata_estimator_insert (struct MultiStrataEstimator *se,
159 struct IBF_Key key);
160
161
162/**
163 * Remove a key from the strata estimator.
164 *
165 * @param se strata estimator to remove the key from
166 * @param key key to remove
167 */
168void
169strata_estimator_remove (struct MultiStrataEstimator *se,
170 struct IBF_Key key);
171
172
173/**
174 * Destroy a strata estimator, free all of its resources.
175 *
176 * @param se strata estimator to destroy.
177 */
178void
179strata_estimator_destroy (struct MultiStrataEstimator *se);
180
181
182/**
183 * Make a copy of a strata estimator.
184 *
185 * @param se the strata estimator to copy
186 * @return the copy
187 */
188struct MultiStrataEstimator *
189strata_estimator_dup (struct MultiStrataEstimator *se);
190
191
192#if 0 /* keep Emacsens' auto-indent happy */
193{
194#endif
195#ifdef __cplusplus
196}
197#endif
198
199#endif