aboutsummaryrefslogtreecommitdiff
path: root/src/set/gnunet-service-set_union_strata_estimator.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-11-27 14:14:24 +0000
committerChristian Grothoff <christian@grothoff.org>2014-11-27 14:14:24 +0000
commit8eac129743fb8a319b49b8344a01d618b0eb46d3 (patch)
treee6f5af012b088997bf60da7576d480dc0f429365 /src/set/gnunet-service-set_union_strata_estimator.c
parent0d3932d5151f61cf4838123dd7edc66f27c08dfc (diff)
downloadgnunet-8eac129743fb8a319b49b8344a01d618b0eb46d3.tar.gz
gnunet-8eac129743fb8a319b49b8344a01d618b0eb46d3.zip
-dox, indentation
Diffstat (limited to 'src/set/gnunet-service-set_union_strata_estimator.c')
-rw-r--r--src/set/gnunet-service-set_union_strata_estimator.c38
1 files changed, 23 insertions, 15 deletions
diff --git a/src/set/gnunet-service-set_union_strata_estimator.c b/src/set/gnunet-service-set_union_strata_estimator.c
index 2288e25f5..60ecbad7a 100644
--- a/src/set/gnunet-service-set_union_strata_estimator.c
+++ b/src/set/gnunet-service-set_union_strata_estimator.c
@@ -22,7 +22,6 @@
22 * @brief invertible bloom filter 22 * @brief invertible bloom filter
23 * @author Florian Dold 23 * @author Florian Dold
24 */ 24 */
25
26#include "platform.h" 25#include "platform.h"
27#include "gnunet_util_lib.h" 26#include "gnunet_util_lib.h"
28#include "ibf.h" 27#include "ibf.h"
@@ -36,9 +35,10 @@
36 * @param buf buffer to write to, must be of appropriate size 35 * @param buf buffer to write to, must be of appropriate size
37 */ 36 */
38void 37void
39strata_estimator_write (const struct StrataEstimator *se, void *buf) 38strata_estimator_write (const struct StrataEstimator *se,
39 void *buf)
40{ 40{
41 int i; 41 unsigned int i;
42 42
43 GNUNET_assert (NULL != se); 43 GNUNET_assert (NULL != se);
44 for (i = 0; i < se->strata_count; i++) 44 for (i = 0; i < se->strata_count; i++)
@@ -57,9 +57,11 @@ strata_estimator_write (const struct StrataEstimator *se, void *buf)
57 * @param se strata estimator to write to 57 * @param se strata estimator to write to
58 */ 58 */
59void 59void
60strata_estimator_read (const void *buf, struct StrataEstimator *se) 60strata_estimator_read (const void *buf,
61 struct StrataEstimator *se)
61{ 62{
62 int i; 63 unsigned int i;
64
63 for (i = 0; i < se->strata_count; i++) 65 for (i = 0; i < se->strata_count; i++)
64 { 66 {
65 ibf_read_slice (buf, 0, se->ibf_size, se->strata[i]); 67 ibf_read_slice (buf, 0, se->ibf_size, se->strata[i]);
@@ -75,10 +77,12 @@ strata_estimator_read (const void *buf, struct StrataEstimator *se)
75 * @param key key to add 77 * @param key key to add
76 */ 78 */
77void 79void
78strata_estimator_insert (struct StrataEstimator *se, struct IBF_Key key) 80strata_estimator_insert (struct StrataEstimator *se,
81 struct IBF_Key key)
79{ 82{
80 uint64_t v; 83 uint64_t v;
81 int i; 84 unsigned int i;
85
82 v = key.key_val; 86 v = key.key_val;
83 /* count trailing '1'-bits of v */ 87 /* count trailing '1'-bits of v */
84 for (i = 0; v & 1; v>>=1, i++) 88 for (i = 0; v & 1; v>>=1, i++)
@@ -94,10 +98,12 @@ strata_estimator_insert (struct StrataEstimator *se, struct IBF_Key key)
94 * @param key key to remove 98 * @param key key to remove
95 */ 99 */
96void 100void
97strata_estimator_remove (struct StrataEstimator *se, struct IBF_Key key) 101strata_estimator_remove (struct StrataEstimator *se,
102 struct IBF_Key key)
98{ 103{
99 uint64_t v; 104 uint64_t v;
100 int i; 105 unsigned int i;
106
101 v = key.key_val; 107 v = key.key_val;
102 /* count trailing '1'-bits of v */ 108 /* count trailing '1'-bits of v */
103 for (i = 0; v & 1; v>>=1, i++) 109 for (i = 0; v & 1; v>>=1, i++)
@@ -115,13 +121,14 @@ strata_estimator_remove (struct StrataEstimator *se, struct IBF_Key key)
115 * @return a freshly allocated, empty strata estimator 121 * @return a freshly allocated, empty strata estimator
116 */ 122 */
117struct StrataEstimator * 123struct StrataEstimator *
118strata_estimator_create (unsigned int strata_count, uint32_t ibf_size, uint8_t ibf_hashnum) 124strata_estimator_create (unsigned int strata_count,
125 uint32_t ibf_size,
126 uint8_t ibf_hashnum)
119{ 127{
120 struct StrataEstimator *se; 128 struct StrataEstimator *se;
121 int i; 129 unsigned int i;
122 130
123 /* fixme: allocate everything in one chunk */ 131 /* fixme: allocate everything in one chunk */
124
125 se = GNUNET_new (struct StrataEstimator); 132 se = GNUNET_new (struct StrataEstimator);
126 se->strata_count = strata_count; 133 se->strata_count = strata_count;
127 se->ibf_size = ibf_size; 134 se->ibf_size = ibf_size;
@@ -146,7 +153,7 @@ strata_estimator_difference (const struct StrataEstimator *se1,
146 const struct StrataEstimator *se2) 153 const struct StrataEstimator *se2)
147{ 154{
148 int i; 155 int i;
149 int count; 156 unsigned int count;
150 157
151 GNUNET_assert (se1->strata_count == se2->strata_count); 158 GNUNET_assert (se1->strata_count == se2->strata_count);
152 count = 0; 159 count = 0;
@@ -155,6 +162,7 @@ strata_estimator_difference (const struct StrataEstimator *se1,
155 struct InvertibleBloomFilter *diff; 162 struct InvertibleBloomFilter *diff;
156 /* number of keys decoded from the ibf */ 163 /* number of keys decoded from the ibf */
157 int ibf_count; 164 int ibf_count;
165
158 /* FIXME: implement this without always allocating new IBFs */ 166 /* FIXME: implement this without always allocating new IBFs */
159 diff = ibf_dup (se1->strata[i]); 167 diff = ibf_dup (se1->strata[i]);
160 ibf_subtract (diff, se2->strata[i]); 168 ibf_subtract (diff, se2->strata[i]);
@@ -191,7 +199,7 @@ struct StrataEstimator *
191strata_estimator_dup (struct StrataEstimator *se) 199strata_estimator_dup (struct StrataEstimator *se)
192{ 200{
193 struct StrataEstimator *c; 201 struct StrataEstimator *c;
194 int i; 202 unsigned int i;
195 203
196 c = GNUNET_new (struct StrataEstimator); 204 c = GNUNET_new (struct StrataEstimator);
197 c->strata_count = se->strata_count; 205 c->strata_count = se->strata_count;
@@ -211,7 +219,7 @@ strata_estimator_dup (struct StrataEstimator *se)
211void 219void
212strata_estimator_destroy (struct StrataEstimator *se) 220strata_estimator_destroy (struct StrataEstimator *se)
213{ 221{
214 int i; 222 unsigned int i;
215 223
216 for (i = 0; i < se->strata_count; i++) 224 for (i = 0; i < se->strata_count; i++)
217 ibf_destroy (se->strata[i]); 225 ibf_destroy (se->strata[i]);