aboutsummaryrefslogtreecommitdiff
path: root/src/set
diff options
context:
space:
mode:
Diffstat (limited to 'src/set')
-rw-r--r--src/set/gnunet-set-ibf-profiler.c150
1 files changed, 85 insertions, 65 deletions
diff --git a/src/set/gnunet-set-ibf-profiler.c b/src/set/gnunet-set-ibf-profiler.c
index d45669dc7..1e3f78595 100644
--- a/src/set/gnunet-set-ibf-profiler.c
+++ b/src/set/gnunet-set-ibf-profiler.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -56,16 +56,17 @@ register_hashcode (struct GNUNET_HashCode *hash)
56 struct IBF_Key key; 56 struct IBF_Key key;
57 key = ibf_key_from_hashcode (hash); 57 key = ibf_key_from_hashcode (hash);
58 ibf_hashcode_from_key (key, &replicated); 58 ibf_hashcode_from_key (key, &replicated);
59 (void) GNUNET_CONTAINER_multihashmap_put (key_to_hashcode, 59 (void) GNUNET_CONTAINER_multihashmap_put (
60 &replicated, 60 key_to_hashcode,
61 GNUNET_memdup (hash, sizeof *hash), 61 &replicated,
62 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 62 GNUNET_memdup (hash, sizeof *hash),
63 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
63} 64}
64 65
65 66
66static void 67static void
67iter_hashcodes (struct IBF_Key key, 68iter_hashcodes (struct IBF_Key key,
68 GNUNET_CONTAINER_HashMapIterator iter, 69 GNUNET_CONTAINER_MulitHashMapIteratorCallback iter,
69 void *cls) 70 void *cls)
70{ 71{
71 struct GNUNET_HashCode replicated; 72 struct GNUNET_HashCode replicated;
@@ -73,14 +74,13 @@ iter_hashcodes (struct IBF_Key key,
73 ibf_hashcode_from_key (key, &replicated); 74 ibf_hashcode_from_key (key, &replicated);
74 GNUNET_CONTAINER_multihashmap_get_multiple (key_to_hashcode, 75 GNUNET_CONTAINER_multihashmap_get_multiple (key_to_hashcode,
75 &replicated, 76 &replicated,
76 iter, cls); 77 iter,
78 cls);
77} 79}
78 80
79 81
80static int 82static int
81insert_iterator (void *cls, 83insert_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
82 const struct GNUNET_HashCode *key,
83 void *value)
84{ 84{
85 struct InvertibleBloomFilter *ibf = cls; 85 struct InvertibleBloomFilter *ibf = cls;
86 86
@@ -90,9 +90,7 @@ insert_iterator (void *cls,
90 90
91 91
92static int 92static int
93remove_iterator (void *cls, 93remove_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
94 const struct GNUNET_HashCode *key,
95 void *value)
96{ 94{
97 struct GNUNET_CONTAINER_MultiHashMap *hashmap = cls; 95 struct GNUNET_CONTAINER_MultiHashMap *hashmap = cls;
98 /* if remove fails, there just was a collision with another key */ 96 /* if remove fails, there just was a collision with another key */
@@ -115,18 +113,27 @@ run (void *cls,
115 struct GNUNET_TIME_Absolute start_time; 113 struct GNUNET_TIME_Absolute start_time;
116 struct GNUNET_TIME_Relative delta_time; 114 struct GNUNET_TIME_Relative delta_time;
117 115
118 set_a = GNUNET_CONTAINER_multihashmap_create (((asize == 0) ? 1 : (asize + csize)), 116 set_a =
119 GNUNET_NO); 117 GNUNET_CONTAINER_multihashmap_create (((asize == 0) ? 1 : (asize + csize)),
120 set_b = GNUNET_CONTAINER_multihashmap_create (((bsize == 0) ? 1 : (bsize + csize)), 118 GNUNET_NO);
121 GNUNET_NO); 119 set_b =
120 GNUNET_CONTAINER_multihashmap_create (((bsize == 0) ? 1 : (bsize + csize)),
121 GNUNET_NO);
122 set_c = GNUNET_CONTAINER_multihashmap_create (((csize == 0) ? 1 : csize), 122 set_c = GNUNET_CONTAINER_multihashmap_create (((csize == 0) ? 1 : csize),
123 GNUNET_NO); 123 GNUNET_NO);
124 124
125 key_to_hashcode = GNUNET_CONTAINER_multihashmap_create (((asize+bsize+csize == 0) ? 1 : (asize+bsize+csize)), 125 key_to_hashcode =
126 GNUNET_NO); 126 GNUNET_CONTAINER_multihashmap_create (((asize + bsize + csize == 0)
127 ? 1
128 : (asize + bsize + csize)),
129 GNUNET_NO);
127 130
128 printf ("hash-num=%u, size=%u, #(A-B)=%u, #(B-A)=%u, #(A&B)=%u\n", 131 printf ("hash-num=%u, size=%u, #(A-B)=%u, #(B-A)=%u, #(A&B)=%u\n",
129 hash_num, ibf_size, asize, bsize, csize); 132 hash_num,
133 ibf_size,
134 asize,
135 bsize,
136 csize);
130 137
131 i = 0; 138 i = 0;
132 while (i < asize) 139 while (i < asize)
@@ -135,8 +142,11 @@ run (void *cls,
135 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_a, &id)) 142 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_a, &id))
136 continue; 143 continue;
137 GNUNET_break (GNUNET_OK == 144 GNUNET_break (GNUNET_OK ==
138 GNUNET_CONTAINER_multihashmap_put (set_a, &id, NULL, 145 GNUNET_CONTAINER_multihashmap_put (
139 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 146 set_a,
147 &id,
148 NULL,
149 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
140 register_hashcode (&id); 150 register_hashcode (&id);
141 i++; 151 i++;
142 } 152 }
@@ -149,8 +159,11 @@ run (void *cls,
149 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_b, &id)) 159 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_b, &id))
150 continue; 160 continue;
151 GNUNET_break (GNUNET_OK == 161 GNUNET_break (GNUNET_OK ==
152 GNUNET_CONTAINER_multihashmap_put (set_b, &id, NULL, 162 GNUNET_CONTAINER_multihashmap_put (
153 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 163 set_b,
164 &id,
165 NULL,
166 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
154 register_hashcode (&id); 167 register_hashcode (&id);
155 i++; 168 i++;
156 } 169 }
@@ -165,16 +178,18 @@ run (void *cls,
165 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_c, &id)) 178 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_c, &id))
166 continue; 179 continue;
167 GNUNET_break (GNUNET_OK == 180 GNUNET_break (GNUNET_OK ==
168 GNUNET_CONTAINER_multihashmap_put (set_c, &id, NULL, 181 GNUNET_CONTAINER_multihashmap_put (
169 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 182 set_c,
183 &id,
184 NULL,
185 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
170 register_hashcode (&id); 186 register_hashcode (&id);
171 i++; 187 i++;
172 } 188 }
173 189
174 ibf_a = ibf_create (ibf_size, hash_num); 190 ibf_a = ibf_create (ibf_size, hash_num);
175 ibf_b = ibf_create (ibf_size, hash_num); 191 ibf_b = ibf_create (ibf_size, hash_num);
176 if ( (NULL == ibf_a) || 192 if ((NULL == ibf_a) || (NULL == ibf_b))
177 (NULL == ibf_b) )
178 { 193 {
179 /* insufficient memory */ 194 /* insufficient memory */
180 GNUNET_break (0); 195 GNUNET_break (0);
@@ -195,8 +210,7 @@ run (void *cls,
195 delta_time = GNUNET_TIME_absolute_get_duration (start_time); 210 delta_time = GNUNET_TIME_absolute_get_duration (start_time);
196 211
197 printf ("encoded in: %s\n", 212 printf ("encoded in: %s\n",
198 GNUNET_STRINGS_relative_time_to_string (delta_time, 213 GNUNET_STRINGS_relative_time_to_string (delta_time, GNUNET_NO));
199 GNUNET_NO));
200 214
201 ibf_subtract (ibf_a, ibf_b); 215 ibf_subtract (ibf_a, ibf_b);
202 216
@@ -209,8 +223,9 @@ run (void *cls,
209 if (GNUNET_SYSERR == res) 223 if (GNUNET_SYSERR == res)
210 { 224 {
211 printf ("decode failed, %u/%u elements left\n", 225 printf ("decode failed, %u/%u elements left\n",
212 GNUNET_CONTAINER_multihashmap_size (set_a) + GNUNET_CONTAINER_multihashmap_size (set_b), 226 GNUNET_CONTAINER_multihashmap_size (set_a) +
213 asize + bsize); 227 GNUNET_CONTAINER_multihashmap_size (set_b),
228 asize + bsize);
214 return; 229 return;
215 } 230 }
216 if (GNUNET_NO == res) 231 if (GNUNET_NO == res)
@@ -220,8 +235,7 @@ run (void *cls,
220 { 235 {
221 delta_time = GNUNET_TIME_absolute_get_duration (start_time); 236 delta_time = GNUNET_TIME_absolute_get_duration (start_time);
222 printf ("decoded successfully in: %s\n", 237 printf ("decoded successfully in: %s\n",
223 GNUNET_STRINGS_relative_time_to_string (delta_time, 238 GNUNET_STRINGS_relative_time_to_string (delta_time, GNUNET_NO));
224 GNUNET_NO));
225 } 239 }
226 else 240 else
227 { 241 {
@@ -235,9 +249,10 @@ run (void *cls,
235 if (side == -1) 249 if (side == -1)
236 iter_hashcodes (ibf_key, remove_iterator, set_b); 250 iter_hashcodes (ibf_key, remove_iterator, set_b);
237 } 251 }
238 printf("cyclic IBF, %u/%u elements left\n", 252 printf ("cyclic IBF, %u/%u elements left\n",
239 GNUNET_CONTAINER_multihashmap_size (set_a) + GNUNET_CONTAINER_multihashmap_size (set_b), 253 GNUNET_CONTAINER_multihashmap_size (set_a) +
240 asize + bsize); 254 GNUNET_CONTAINER_multihashmap_size (set_b),
255 asize + bsize);
241} 256}
242 257
243 258
@@ -247,40 +262,45 @@ main (int argc, char **argv)
247 struct GNUNET_GETOPT_CommandLineOption options[] = { 262 struct GNUNET_GETOPT_CommandLineOption options[] = {
248 263
249 GNUNET_GETOPT_option_uint ('A', 264 GNUNET_GETOPT_option_uint ('A',
250 "asize", 265 "asize",
251 NULL, 266 NULL,
252 gettext_noop ("number of element in set A-B"), 267 gettext_noop ("number of element in set A-B"),
253 &asize), 268 &asize),
254 269
255 GNUNET_GETOPT_option_uint ('B', 270 GNUNET_GETOPT_option_uint ('B',
256 "bsize", 271 "bsize",
257 NULL, 272 NULL,
258 gettext_noop ("number of element in set B-A"), 273 gettext_noop ("number of element in set B-A"),
259 &bsize), 274 &bsize),
260 275
261 GNUNET_GETOPT_option_uint ('C', 276 GNUNET_GETOPT_option_uint ('C',
262 "csize", 277 "csize",
263 NULL, 278 NULL,
264 gettext_noop ("number of common elements in A and B"), 279 gettext_noop (
265 &csize), 280 "number of common elements in A and B"),
266 281 &csize),
282
267 GNUNET_GETOPT_option_uint ('k', 283 GNUNET_GETOPT_option_uint ('k',
268 "hash-num", 284 "hash-num",
269 NULL, 285 NULL,
270 gettext_noop ("hash num"), 286 gettext_noop ("hash num"),
271 &hash_num), 287 &hash_num),
272 288
273 GNUNET_GETOPT_option_uint ('s', 289 GNUNET_GETOPT_option_uint ('s',
274 "ibf-size", 290 "ibf-size",
275 NULL, 291 NULL,
276 gettext_noop ("ibf size"), 292 gettext_noop ("ibf size"),
277 &ibf_size), 293 &ibf_size),
278 294
279 GNUNET_GETOPT_OPTION_END 295 GNUNET_GETOPT_OPTION_END};
280 }; 296
281 297 GNUNET_PROGRAM_run2 (argc,
282 GNUNET_PROGRAM_run2 (argc, argv, "gnunet-consensus-ibf", 298 argv,
283 "help", 299 "gnunet-consensus-ibf",
284 options, &run, NULL, GNUNET_YES); 300 "help",
301 options,
302 &run,
303 NULL,
304 GNUNET_YES);
285 return 0; 305 return 0;
286} 306}