remove CYGWIN codeblocks, drop vendored Windows openvpn, drop win32 specific files.
[oweals/gnunet.git] / src / set / gnunet-service-set_union_strata_estimator.h
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-set_union_strata_estimator.h
23  * @brief estimator of set difference
24  * @author Florian Dold
25  */
26
27 #ifndef GNUNET_CONSENSUS_STRATA_ESTIMATOR_H
28 #define GNUNET_CONSENSUS_STRATA_ESTIMATOR_H
29
30 #include "platform.h"
31 #include "gnunet_common.h"
32 #include "gnunet_util_lib.h"
33
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #if 0                           /* keep Emacsens' auto-indent happy */
38 }
39 #endif
40 #endif
41
42
43 /**
44  * A handle to a strata estimator.
45  */
46 struct StrataEstimator {
47   /**
48    * The IBFs of this strata estimator.
49    */
50   struct InvertibleBloomFilter **strata;
51
52   /**
53    * Size of the IBF array in @e strata
54    */
55   unsigned int strata_count;
56
57   /**
58    * Size of each IBF stratum (in bytes)
59    */
60   unsigned int ibf_size;
61 };
62
63
64 /**
65  * Write the given strata estimator to the buffer.
66  *
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
70  */
71 size_t
72 strata_estimator_write(const struct StrataEstimator *se,
73                        void *buf);
74
75
76 /**
77  * Read strata from the buffer into the given strata
78  * estimator.  The strata estimator must already be allocated.
79  *
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
85  */
86 int
87 strata_estimator_read(const void *buf,
88                       size_t buf_len,
89                       int is_compressed,
90                       struct StrataEstimator *se);
91
92
93 /**
94  * Create a new strata estimator with the given parameters.
95  *
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
100  */
101 struct StrataEstimator *
102 strata_estimator_create(unsigned int strata_count,
103                         uint32_t ibf_size,
104                         uint8_t ibf_hashnum);
105
106
107 /**
108  * Get an estimation of the symmetric difference of the elements
109  * contained in both strata estimators.
110  *
111  * @param se1 first strata estimator
112  * @param se2 second strata estimator
113  * @return abs(|se1| - |se2|)
114  */
115 unsigned int
116 strata_estimator_difference(const struct StrataEstimator *se1,
117                             const struct StrataEstimator *se2);
118
119
120 /**
121  * Add a key to the strata estimator.
122  *
123  * @param se strata estimator to add the key to
124  * @param key key to add
125  */
126 void
127 strata_estimator_insert(struct StrataEstimator *se,
128                         struct IBF_Key key);
129
130
131 /**
132  * Remove a key from the strata estimator.
133  *
134  * @param se strata estimator to remove the key from
135  * @param key key to remove
136  */
137 void
138 strata_estimator_remove(struct StrataEstimator *se,
139                         struct IBF_Key key);
140
141
142 /**
143  * Destroy a strata estimator, free all of its resources.
144  *
145  * @param se strata estimator to destroy.
146  */
147 void
148 strata_estimator_destroy(struct StrataEstimator *se);
149
150
151 /**
152  * Make a copy of a strata estimator.
153  *
154  * @param se the strata estimator to copy
155  * @return the copy
156  */
157 struct StrataEstimator *
158 strata_estimator_dup(struct StrataEstimator *se);
159
160
161 #if 0                           /* keep Emacsens' auto-indent happy */
162 {
163 #endif
164 #ifdef __cplusplus
165 }
166 #endif
167
168 #endif