summaryrefslogtreecommitdiff
path: root/src/common/container.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2008-04-08 17:06:41 +0000
committerNick Mathewson <nickm@torproject.org>2008-04-08 17:06:41 +0000
commita627407fcba1d5b1671e5789f420e4b5f8b63f99 (patch)
treee15ea16047c2352de2100aaa816ead54232cb236 /src/common/container.c
parent0c9efd6a1e252c2d6f495d158fdc1ec6877e0f10 (diff)
downloadtor-a627407fcba1d5b1671e5789f420e4b5f8b63f99.tar.gz
tor-a627407fcba1d5b1671e5789f420e4b5f8b63f99.zip
r19233@catbus: nickm | 2008-04-08 13:06:34 -0400
When we remove old routers, use Bloom filters rather than a digestmap-based set in order to tell which ones we absolutely need to keep. This will save us roughly a kazillion little short-lived allocations for hash table entries. svn:r14318
Diffstat (limited to 'src/common/container.c')
-rw-r--r--src/common/container.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/common/container.c b/src/common/container.c
index a33a70116e..6d3a8fd5f9 100644
--- a/src/common/container.c
+++ b/src/common/container.c
@@ -1192,3 +1192,23 @@ IMPLEMENT_ORDER_FUNC(find_nth_double, double)
IMPLEMENT_ORDER_FUNC(find_nth_uint32, uint32_t)
IMPLEMENT_ORDER_FUNC(find_nth_long, long)
+/** Return a newly allocated digestset_t, optimized to hold a total of
+ * <b>max_elements</b> digests with a reasonably low false positive weight. */
+digestset_t *
+digestset_new(int max_elements)
+{
+ int n_bits = 1u << (tor_log2(max_elements)+5);
+ digestset_t *r = tor_malloc(sizeof(digestset_t));
+ r->mask = n_bits - 1;
+ r->ba = bitarray_init_zero(n_bits);
+ return r;
+}
+
+/** Free all storage held in <b>set</b>. */
+void
+digestset_free(digestset_t *set)
+{
+ bitarray_free(set->ba);
+ tor_free(set);
+}
+