diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-10-08 11:30:19 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-10-08 11:30:19 +0000 |
commit | ae53a8d1d043cbd5967fb01316a32685c7a8af9b (patch) | |
tree | a8d791aed993ac8691f68ee6152a6ffb14a88ee3 /src/set/ibf.c | |
parent | e105a542a8ddb22184712bfe565aa734f1d0349d (diff) | |
download | gnunet-ae53a8d1d043cbd5967fb01316a32685c7a8af9b.tar.gz gnunet-ae53a8d1d043cbd5967fb01316a32685c7a8af9b.zip |
add logic for strata compression
Diffstat (limited to 'src/set/ibf.c')
-rw-r--r-- | src/set/ibf.c | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/src/set/ibf.c b/src/set/ibf.c index 19d15a5b2..0e8e1839e 100644 --- a/src/set/ibf.c +++ b/src/set/ibf.c | |||
@@ -41,7 +41,6 @@ | |||
41 | struct IBF_Key | 41 | struct IBF_Key |
42 | ibf_key_from_hashcode (const struct GNUNET_HashCode *hash) | 42 | ibf_key_from_hashcode (const struct GNUNET_HashCode *hash) |
43 | { | 43 | { |
44 | /* FIXME: endianess */ | ||
45 | return *(struct IBF_Key *) hash; | 44 | return *(struct IBF_Key *) hash; |
46 | } | 45 | } |
47 | 46 | ||
@@ -53,11 +52,13 @@ ibf_key_from_hashcode (const struct GNUNET_HashCode *hash) | |||
53 | * @param dst hashcode to store the result in | 52 | * @param dst hashcode to store the result in |
54 | */ | 53 | */ |
55 | void | 54 | void |
56 | ibf_hashcode_from_key (struct IBF_Key key, struct GNUNET_HashCode *dst) | 55 | ibf_hashcode_from_key (struct IBF_Key key, |
56 | struct GNUNET_HashCode *dst) | ||
57 | { | 57 | { |
58 | struct IBF_Key *p; | 58 | struct IBF_Key *p; |
59 | unsigned int i; | 59 | unsigned int i; |
60 | const unsigned int keys_per_hashcode = sizeof (struct GNUNET_HashCode) / sizeof (struct IBF_Key); | 60 | const unsigned int keys_per_hashcode = sizeof (struct GNUNET_HashCode) / sizeof (struct IBF_Key); |
61 | |||
61 | p = (struct IBF_Key *) dst; | 62 | p = (struct IBF_Key *) dst; |
62 | for (i = 0; i < keys_per_hashcode; i++) | 63 | for (i = 0; i < keys_per_hashcode; i++) |
63 | *p++ = key; | 64 | *p++ = key; |
@@ -69,7 +70,7 @@ ibf_hashcode_from_key (struct IBF_Key key, struct GNUNET_HashCode *dst) | |||
69 | * | 70 | * |
70 | * @param size number of IBF buckets | 71 | * @param size number of IBF buckets |
71 | * @param hash_num number of buckets one element is hashed in | 72 | * @param hash_num number of buckets one element is hashed in |
72 | * @return the newly created invertible bloom filter | 73 | * @return the newly created invertible bloom filter, NULL on error |
73 | */ | 74 | */ |
74 | struct InvertibleBloomFilter * | 75 | struct InvertibleBloomFilter * |
75 | ibf_create (uint32_t size, uint8_t hash_num) | 76 | ibf_create (uint32_t size, uint8_t hash_num) |
@@ -80,20 +81,40 @@ ibf_create (uint32_t size, uint8_t hash_num) | |||
80 | 81 | ||
81 | ibf = GNUNET_new (struct InvertibleBloomFilter); | 82 | ibf = GNUNET_new (struct InvertibleBloomFilter); |
82 | ibf->count = GNUNET_malloc_large (size * sizeof (uint8_t)); | 83 | ibf->count = GNUNET_malloc_large (size * sizeof (uint8_t)); |
84 | if (NULL == ibf->count) | ||
85 | { | ||
86 | GNUNET_free (ibf); | ||
87 | return NULL; | ||
88 | } | ||
83 | ibf->key_sum = GNUNET_malloc_large (size * sizeof (struct IBF_Key)); | 89 | ibf->key_sum = GNUNET_malloc_large (size * sizeof (struct IBF_Key)); |
90 | if (NULL == ibf->key_sum) | ||
91 | { | ||
92 | GNUNET_free (ibf->count); | ||
93 | GNUNET_free (ibf); | ||
94 | return NULL; | ||
95 | } | ||
84 | ibf->key_hash_sum = GNUNET_malloc_large (size * sizeof (struct IBF_KeyHash)); | 96 | ibf->key_hash_sum = GNUNET_malloc_large (size * sizeof (struct IBF_KeyHash)); |
97 | if (NULL == ibf->key_hash_sum) | ||
98 | { | ||
99 | GNUNET_free (ibf->key_sum); | ||
100 | GNUNET_free (ibf->count); | ||
101 | GNUNET_free (ibf); | ||
102 | return NULL; | ||
103 | } | ||
85 | ibf->size = size; | 104 | ibf->size = size; |
86 | ibf->hash_num = hash_num; | 105 | ibf->hash_num = hash_num; |
87 | 106 | ||
88 | return ibf; | 107 | return ibf; |
89 | } | 108 | } |
90 | 109 | ||
110 | |||
91 | /** | 111 | /** |
92 | * Store unique bucket indices for the specified key in dst. | 112 | * Store unique bucket indices for the specified key in dst. |
93 | */ | 113 | */ |
94 | static inline void | 114 | static void |
95 | ibf_get_indices (const struct InvertibleBloomFilter *ibf, | 115 | ibf_get_indices (const struct InvertibleBloomFilter *ibf, |
96 | struct IBF_Key key, int *dst) | 116 | struct IBF_Key key, |
117 | int *dst) | ||
97 | { | 118 | { |
98 | uint32_t filled; | 119 | uint32_t filled; |
99 | uint32_t i; | 120 | uint32_t i; |
@@ -371,4 +392,3 @@ ibf_destroy (struct InvertibleBloomFilter *ibf) | |||
371 | GNUNET_free (ibf->count); | 392 | GNUNET_free (ibf->count); |
372 | GNUNET_free (ibf); | 393 | GNUNET_free (ibf); |
373 | } | 394 | } |
374 | |||