-renaming
[oweals/gnunet.git] / src / set / gnunet-service-set_union_strata_estimator.h
1 /*
2       This file is part of GNUnet
3       (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., 59 Temple Place - Suite 330,
18       Boston, MA 02111-1307, 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   struct InvertibleBloomFilter **strata;
49   unsigned int strata_count;
50   unsigned int ibf_size;
51 };
52
53
54 /**
55  * Write the given strata estimator to the buffer.
56  *
57  * @param se strata estimator to serialize
58  * @param buf buffer to write to, must be of appropriate size
59  */
60 void
61 strata_estimator_write (const struct StrataEstimator *se, void *buf);
62
63
64 /**
65  * Read strata from the buffer into the given strata
66  * estimator.  The strata estimator must already be allocated.
67  *
68  * @param buf buffer to read from
69  * @param se strata estimator to write to
70  */
71 void
72 strata_estimator_read (const void *buf, struct StrataEstimator *se);
73
74
75 /**
76  * Create a new strata estimator with the given parameters.
77  *
78  * @param strata_count number of stratas, that is, number of ibfs in the estimator
79  * @param ibf_size size of each ibf stratum
80  * @param ibf_hashnum hashnum parameter of each ibf
81  * @return a freshly allocated, empty strata estimator
82  */
83 struct StrataEstimator *
84 strata_estimator_create (unsigned int strata_count, uint32_t ibf_size, uint8_t ibf_hashnum);
85
86
87 /**
88  * Get an estimation of the symmetric difference of the elements
89  * contained in both strata estimators.
90  *
91  * @param se1 first strata estimator
92  * @param se2 second strata estimator
93  * @return abs(|se1| - |se2|)
94  */
95 unsigned int
96 strata_estimator_difference (const struct StrataEstimator *se1,
97                              const struct StrataEstimator *se2);
98
99
100 /**
101  * Add a key to the strata estimator.
102  *
103  * @param se strata estimator to add the key to
104  * @param key key to add
105  */
106 void
107 strata_estimator_insert (struct StrataEstimator *se, struct IBF_Key key);
108
109
110 /**
111  * Remove a key from the strata estimator.
112  *
113  * @param se strata estimator to remove the key from
114  * @param key key to remove
115  */
116 void
117 strata_estimator_remove (struct StrataEstimator *se, struct IBF_Key key);
118
119
120 /**
121  * Destroy a strata estimator, free all of its resources.
122  *
123  * @param se strata estimator to destroy.
124  */
125 void
126 strata_estimator_destroy (struct StrataEstimator *se);
127
128
129 /**
130  * Make a copy of a strata estimator.
131  *
132  * @param se the strata estimator to copy
133  * @return the copy
134  */
135 struct StrataEstimator *
136 strata_estimator_dup (struct StrataEstimator *se);
137
138
139 #if 0                           /* keep Emacsens' auto-indent happy */
140 {
141 #endif
142 #ifdef __cplusplus
143 }
144 #endif
145
146 #endif
147