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