aboutsummaryrefslogtreecommitdiff
path: root/src/block/bg_bf.c
diff options
context:
space:
mode:
authorxrs <xrs@mail36.net>2017-02-28 19:37:43 +0100
committerxrs <xrs@mail36.net>2017-02-28 19:37:43 +0100
commitf82b3a27df765f4a31548ae4efe66dc3dbc42cef (patch)
tree5a08cd0026d2b85bca3160b6ca40573c871c8635 /src/block/bg_bf.c
parentb0042448a40e90426ea8013b1abba8b2ecb69c2b (diff)
parenta9a6b98c54f5cc3e680c8ea2f9c69e3955e2a7da (diff)
downloadgnunet-f82b3a27df765f4a31548ae4efe66dc3dbc42cef.tar.gz
gnunet-f82b3a27df765f4a31548ae4efe66dc3dbc42cef.zip
Merge branch 'master' of ssh://gnunet.org/gnunet
Conflicts: src/multicast/test_multicast_multipeer.c
Diffstat (limited to 'src/block/bg_bf.c')
-rw-r--r--src/block/bg_bf.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/block/bg_bf.c b/src/block/bg_bf.c
index 9c4dc9060..1a17ec84e 100644
--- a/src/block/bg_bf.c
+++ b/src/block/bg_bf.c
@@ -232,4 +232,36 @@ GNUNET_BLOCK_GROUP_bf_test_and_set (struct GNUNET_BLOCK_Group *bg,
232} 232}
233 233
234 234
235/**
236 * How many bytes should a bloomfilter be if we have already seen
237 * entry_count responses? Sized so that do not have to
238 * re-size the filter too often (to keep it cheap).
239 *
240 * Since other peers will also add entries but not resize the filter,
241 * we should generally pick a slightly larger size than what the
242 * strict math would suggest.
243 *
244 * @param entry_count expected number of entries in the Bloom filter
245 * @param k number of bits set per entry
246 * @return must be a power of two and smaller or equal to 2^15.
247 */
248size_t
249GNUNET_BLOCK_GROUP_compute_bloomfilter_size (unsigned int entry_count,
250 unsigned int k)
251{
252 size_t size;
253 unsigned int ideal = (entry_count * k) / 4;
254 uint16_t max = 1 << 15;
255
256 if (entry_count > max)
257 return max;
258 size = 8;
259 while ((size < max) && (size < ideal))
260 size *= 2;
261 if (size > max)
262 return max;
263 return size;
264}
265
266
235/* end of bg_bf.c */ 267/* end of bg_bf.c */