aboutsummaryrefslogtreecommitdiff
path: root/src/set/ibf.c
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2013-06-19 10:48:54 +0000
committerFlorian Dold <florian.dold@gmail.com>2013-06-19 10:48:54 +0000
commita900b29ddaa9ea46c731b054b5e3ef3e725b95a8 (patch)
tree52e1a9697b0abf4618cd5684359ec5f0a040898a /src/set/ibf.c
parent17353bc0a47c89bda205f23e7995377c9bfe7769 (diff)
downloadgnunet-a900b29ddaa9ea46c731b054b5e3ef3e725b95a8.tar.gz
gnunet-a900b29ddaa9ea46c731b054b5e3ef3e725b95a8.zip
- opaque mq structs
- mq for mesh - faster hashing for IBFs - mesh replaces stream in set - new set profiler (work in progress)
Diffstat (limited to 'src/set/ibf.c')
-rw-r--r--src/set/ibf.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/src/set/ibf.c b/src/set/ibf.c
index 383ce3daf..e3c5be59a 100644
--- a/src/set/ibf.c
+++ b/src/set/ibf.c
@@ -19,7 +19,7 @@
19*/ 19*/
20 20
21/** 21/**
22 * @file consensus/ibf.c 22 * @file set/ibf.c
23 * @brief implementation of the invertible bloom filter 23 * @brief implementation of the invertible bloom filter
24 * @author Florian Dold 24 * @author Florian Dold
25 */ 25 */
@@ -27,6 +27,12 @@
27#include "ibf.h" 27#include "ibf.h"
28 28
29/** 29/**
30 * Compute the key's hash from the key.
31 * Redefine to use a different hash function.
32 */
33#define IBF_KEY_HASH_VAL(k) (GNUNET_CRYPTO_crc32_n (&(k), sizeof (struct IBF_KeyHash)))
34
35/**
30 * Create a key from a hashcode. 36 * Create a key from a hashcode.
31 * 37 *
32 * @param hash the hashcode 38 * @param hash the hashcode
@@ -89,23 +95,21 @@ static inline void
89ibf_get_indices (const struct InvertibleBloomFilter *ibf, 95ibf_get_indices (const struct InvertibleBloomFilter *ibf,
90 struct IBF_Key key, int *dst) 96 struct IBF_Key key, int *dst)
91{ 97{
92 struct GNUNET_HashCode bucket_indices; 98 uint32_t filled;
93 unsigned int filled; 99 uint32_t i;
94 int i; 100 uint32_t bucket = key.key_val & 0xFFFFFFFF;
95 GNUNET_CRYPTO_hash (&key, sizeof key, &bucket_indices); 101
96 filled = 0; 102 for (i = 0, filled=0; filled < ibf->hash_num; i++)
97 for (i = 0; filled < ibf->hash_num; i++)
98 { 103 {
99 unsigned int bucket;
100 unsigned int j; 104 unsigned int j;
101 if ( (0 != i) && (0 == (i % 16)) ) 105 uint64_t x;
102 GNUNET_CRYPTO_hash (&bucket_indices, sizeof (struct GNUNET_HashCode), &bucket_indices);
103 bucket = bucket_indices.bits[i % 16] % ibf->size;
104 for (j = 0; j < filled; j++) 106 for (j = 0; j < filled; j++)
105 if (dst[j] == bucket) 107 if (dst[j] == bucket)
106 goto try_next; 108 goto try_next;
107 dst[filled++] = bucket; 109 dst[filled++] = bucket % ibf->size;
108 try_next: ; 110 try_next: ;
111 x = ((uint64_t) bucket << 32) | i;
112 bucket = GNUNET_CRYPTO_crc32_n (&x, sizeof x);
109 } 113 }
110} 114}
111 115
@@ -116,16 +120,14 @@ ibf_insert_into (struct InvertibleBloomFilter *ibf,
116 const int *buckets, int side) 120 const int *buckets, int side)
117{ 121{
118 int i; 122 int i;
119 struct GNUNET_HashCode key_hash_sha; 123
120 struct IBF_KeyHash key_hash;
121 GNUNET_CRYPTO_hash (&key, sizeof key, &key_hash_sha);
122 key_hash.key_hash_val = key_hash_sha.bits[0];
123 for (i = 0; i < ibf->hash_num; i++) 124 for (i = 0; i < ibf->hash_num; i++)
124 { 125 {
125 const int bucket = buckets[i]; 126 const int bucket = buckets[i];
126 ibf->count[bucket].count_val += side; 127 ibf->count[bucket].count_val += side;
127 ibf->key_sum[bucket].key_val ^= key.key_val; 128 ibf->key_sum[bucket].key_val ^= key.key_val;
128 ibf->key_hash_sum[bucket].key_hash_val ^= key_hash.key_hash_val; 129 ibf->key_hash_sum[bucket].key_hash_val
130 ^= IBF_KEY_HASH_VAL (key);
129 } 131 }
130} 132}
131 133
@@ -183,7 +185,6 @@ ibf_decode (struct InvertibleBloomFilter *ibf,
183{ 185{
184 struct IBF_KeyHash hash; 186 struct IBF_KeyHash hash;
185 int i; 187 int i;
186 struct GNUNET_HashCode key_hash_sha;
187 int buckets[ibf->hash_num]; 188 int buckets[ibf->hash_num];
188 189
189 GNUNET_assert (NULL != ibf); 190 GNUNET_assert (NULL != ibf);
@@ -197,8 +198,7 @@ ibf_decode (struct InvertibleBloomFilter *ibf,
197 if ((1 != ibf->count[i].count_val) && (-1 != ibf->count[i].count_val)) 198 if ((1 != ibf->count[i].count_val) && (-1 != ibf->count[i].count_val))
198 continue; 199 continue;
199 200
200 GNUNET_CRYPTO_hash (&ibf->key_sum[i], sizeof (struct IBF_Key), &key_hash_sha); 201 hash.key_hash_val = IBF_KEY_HASH_VAL (ibf->key_sum[i]);
201 hash.key_hash_val = key_hash_sha.bits[0];
202 202
203 /* test if the hash matches the key */ 203 /* test if the hash matches the key */
204 if (hash.key_hash_val != ibf->key_hash_sum[i].key_hash_val) 204 if (hash.key_hash_val != ibf->key_hash_sum[i].key_hash_val)