aboutsummaryrefslogtreecommitdiff
path: root/src/consensus
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-12-21 12:21:41 +0000
committerChristian Grothoff <christian@grothoff.org>2012-12-21 12:21:41 +0000
commit4b5c027b621db681ecaa87d6ee262e2b54500a7c (patch)
treeabf26854f1f42d9e652a888e419984761626a50a /src/consensus
parentefd13aec28a4576c98d19c4022b1bc36648b3cdc (diff)
downloadgnunet-4b5c027b621db681ecaa87d6ee262e2b54500a7c.tar.gz
gnunet-4b5c027b621db681ecaa87d6ee262e2b54500a7c.zip
-no alloca
Diffstat (limited to 'src/consensus')
-rw-r--r--src/consensus/ibf.c65
1 files changed, 33 insertions, 32 deletions
diff --git a/src/consensus/ibf.c b/src/consensus/ibf.c
index 84d87dfed..1f4e48c29 100644
--- a/src/consensus/ibf.c
+++ b/src/consensus/ibf.c
@@ -113,49 +113,50 @@ ibf_insert_on_side (struct InvertibleBloomFilter *ibf,
113 struct GNUNET_HashCode bucket_indices; 113 struct GNUNET_HashCode bucket_indices;
114 struct GNUNET_HashCode key_copy; 114 struct GNUNET_HashCode key_copy;
115 struct GNUNET_HashCode key_hash; 115 struct GNUNET_HashCode key_hash;
116 int *used_buckets;
117 unsigned int i; 116 unsigned int i;
118 117
119 118
120 GNUNET_assert ((1 == side) || (-1 == side)); 119 GNUNET_assert ((1 == side) || (-1 == side));
121 GNUNET_assert (NULL != ibf); 120 GNUNET_assert (NULL != ibf);
122 121
123 used_buckets = alloca (ibf->hash_num * sizeof (int)); 122 {
124 123 int used_buckets[ibf->hash_num];
125 /* copy the key, if key and an entry in the IBF alias */
126 key_copy = *key;
127 124
128 bucket_indices = key_copy; 125 /* copy the key, if key and an entry in the IBF alias */
129 GNUNET_CRYPTO_hash (key, sizeof (struct GNUNET_HashCode), &key_hash); 126 key_copy = *key;
130 127
131 for (i = 0; i < ibf->hash_num; i++) 128 bucket_indices = key_copy;
132 { 129 GNUNET_CRYPTO_hash (key, sizeof (struct GNUNET_HashCode), &key_hash);
133 unsigned int bucket;
134 unsigned int j;
135 int collided;
136 130
137 if ((i % 16) == 0) 131 for (i = 0; i < ibf->hash_num; i++)
138 GNUNET_CRYPTO_hash (&bucket_indices, sizeof (struct GNUNET_HashCode),
139 &bucket_indices);
140
141 bucket = bucket_indices.bits[i%16] % ibf->size;
142 collided = GNUNET_NO;
143 for (j = 0; j < i; j++)
144 if (used_buckets[j] == bucket)
145 collided = GNUNET_YES;
146 if (GNUNET_YES == collided)
147 { 132 {
148 used_buckets[i] = -1; 133 unsigned int bucket;
149 continue; 134 unsigned int j;
150 } 135 int collided;
151 used_buckets[i] = bucket;
152
153 ibf->count[bucket] += side;
154 136
155 GNUNET_CRYPTO_hash_xor (&key_copy, &ibf->id_sum[bucket], 137 if ((i % 16) == 0)
156 &ibf->id_sum[bucket]); 138 GNUNET_CRYPTO_hash (&bucket_indices, sizeof (struct GNUNET_HashCode),
157 GNUNET_CRYPTO_hash_xor (&key_hash, &ibf->hash_sum[bucket], 139 &bucket_indices);
158 &ibf->hash_sum[bucket]); 140
141 bucket = bucket_indices.bits[i%16] % ibf->size;
142 collided = GNUNET_NO;
143 for (j = 0; j < i; j++)
144 if (used_buckets[j] == bucket)
145 collided = GNUNET_YES;
146 if (GNUNET_YES == collided)
147 {
148 used_buckets[i] = -1;
149 continue;
150 }
151 used_buckets[i] = bucket;
152
153 ibf->count[bucket] += side;
154
155 GNUNET_CRYPTO_hash_xor (&key_copy, &ibf->id_sum[bucket],
156 &ibf->id_sum[bucket]);
157 GNUNET_CRYPTO_hash_xor (&key_hash, &ibf->hash_sum[bucket],
158 &ibf->hash_sum[bucket]);
159 }
159 } 160 }
160} 161}
161 162