2b59e8ed316d7b7514ef8d47ae28ffe785961518
[oweals/gnunet.git] / src / set / gnunet-service-set_union_strata_estimator.h
1 /*
2       This file is part of GNUnet
3       Copyright (C) 2012 Christian Grothoff (and other contributing authors)
4
5       GNUnet is free software; you can redistribute it and/or modify
6       it under the terms of the GNU General Public License as published
7       by the Free Software Foundation; either version 3, or (at your
8       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       General Public License for more details.
14
15       You should have received a copy of the GNU General Public License
16       along with GNUnet; see the file COPYING.  If not, write to the
17       Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18       Boston, MA 02110-1301, USA.
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   /**
49    * The IBFs of this strata estimator.
50    */
51   struct InvertibleBloomFilter **strata;
52
53   /**
54    * Size of the IBF array in @e strata
55    */
56   unsigned int strata_count;
57
58   /**
59    * Size of each IBF stratum (in bytes)
60    */
61   unsigned int ibf_size;
62 };
63
64
65 /**
66  * Write the given strata estimator to the buffer.
67  *
68  * @param se strata estimator to serialize
69  * @param buf buffer to write to, must be of appropriate size
70  */
71 void
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 se strata estimator to write to
82  */
83 void
84 strata_estimator_read (const void *buf,
85                        struct StrataEstimator *se);
86
87
88 /**
89  * Create a new strata estimator with the given parameters.
90  *
91  * @param strata_count number of stratas, that is, number of ibfs in the estimator
92  * @param ibf_size size of each ibf stratum
93  * @param ibf_hashnum hashnum parameter of each ibf
94  * @return a freshly allocated, empty strata estimator
95  */
96 struct StrataEstimator *
97 strata_estimator_create (unsigned int strata_count,
98                          uint32_t ibf_size,
99                          uint8_t ibf_hashnum);
100
101
102 /**
103  * Get an estimation of the symmetric difference of the elements
104  * contained in both strata estimators.
105  *
106  * @param se1 first strata estimator
107  * @param se2 second strata estimator
108  * @return abs(|se1| - |se2|)
109  */
110 unsigned int
111 strata_estimator_difference (const struct StrataEstimator *se1,
112                              const struct StrataEstimator *se2);
113
114
115 /**
116  * Add a key to the strata estimator.
117  *
118  * @param se strata estimator to add the key to
119  * @param key key to add
120  */
121 void
122 strata_estimator_insert (struct StrataEstimator *se,
123                          struct IBF_Key key);
124
125
126 /**
127  * Remove a key from the strata estimator.
128  *
129  * @param se strata estimator to remove the key from
130  * @param key key to remove
131  */
132 void
133 strata_estimator_remove (struct StrataEstimator *se,
134                          struct IBF_Key key);
135
136
137 /**
138  * Destroy a strata estimator, free all of its resources.
139  *
140  * @param se strata estimator to destroy.
141  */
142 void
143 strata_estimator_destroy (struct StrataEstimator *se);
144
145
146 /**
147  * Make a copy of a strata estimator.
148  *
149  * @param se the strata estimator to copy
150  * @return the copy
151  */
152 struct StrataEstimator *
153 strata_estimator_dup (struct StrataEstimator *se);
154
155
156 #if 0                           /* keep Emacsens' auto-indent happy */
157 {
158 #endif
159 #ifdef __cplusplus
160 }
161 #endif
162
163 #endif
164