implementation of the invertible bloom filter More...
Go to the source code of this file.
Macros | |
#define | IBF_KEY_HASH_VAL(k) |
Compute the key's hash from the key. More... | |
Functions | |
struct IBF_Key | ibf_key_from_hashcode (const struct GNUNET_HashCode *hash) |
Create a key from a hashcode. More... | |
void | ibf_hashcode_from_key (struct IBF_Key key, struct GNUNET_HashCode *dst) |
Create a hashcode from a key, by replicating the key until the hascode is filled. More... | |
struct InvertibleBloomFilter * | ibf_create (uint32_t size, uint8_t hash_num) |
Create an invertible bloom filter. More... | |
static void | ibf_get_indices (const struct InvertibleBloomFilter *ibf, struct IBF_Key key, int *dst) |
Store unique bucket indices for the specified key in dst. More... | |
static void | ibf_insert_into (struct InvertibleBloomFilter *ibf, struct IBF_Key key, const int *buckets, int side) |
void | ibf_insert (struct InvertibleBloomFilter *ibf, struct IBF_Key key) |
Insert a key into an IBF. More... | |
void | ibf_remove (struct InvertibleBloomFilter *ibf, struct IBF_Key key) |
Remove a key from an IBF. More... | |
static int | ibf_is_empty (struct InvertibleBloomFilter *ibf) |
Test is the IBF is empty, i.e. More... | |
int | ibf_decode (struct InvertibleBloomFilter *ibf, int *ret_side, struct IBF_Key *ret_id) |
Decode and remove an element from the IBF, if possible. More... | |
void | ibf_write_slice (const struct InvertibleBloomFilter *ibf, uint32_t start, uint32_t count, void *buf) |
Write buckets from an ibf to a buffer. More... | |
void | ibf_read_slice (const void *buf, uint32_t start, uint32_t count, struct InvertibleBloomFilter *ibf) |
Read buckets from a buffer into an ibf. More... | |
void | ibf_subtract (struct InvertibleBloomFilter *ibf1, const struct InvertibleBloomFilter *ibf2) |
Subtract ibf2 from ibf1, storing the result in ibf1. More... | |
struct InvertibleBloomFilter * | ibf_dup (const struct InvertibleBloomFilter *ibf) |
Create a copy of an IBF, the copy has to be destroyed properly. More... | |
void | ibf_destroy (struct InvertibleBloomFilter *ibf) |
Destroy all resources associated with the invertible bloom filter. More... | |
implementation of the invertible bloom filter
Definition in file ibf.c.
#define IBF_KEY_HASH_VAL | ( | k | ) |
Compute the key's hash from the key.
Redefine to use a different hash function.
struct IBF_Key ibf_key_from_hashcode | ( | const struct GNUNET_HashCode * | hash | ) |
Create a key from a hashcode.
hash | the hashcode |
Definition at line 44 of file ibf.c.
Referenced by insert_iterator(), and register_hashcode().
void ibf_hashcode_from_key | ( | struct IBF_Key | key, |
struct GNUNET_HashCode * | dst | ||
) |
Create a hashcode from a key, by replicating the key until the hascode is filled.
key | the key |
dst | hashcode to store the result in |
Definition at line 58 of file ibf.c.
Referenced by iter_hashcodes(), and register_hashcode().
struct InvertibleBloomFilter * ibf_create | ( | uint32_t | size, |
uint8_t | hash_num | ||
) |
Create an invertible bloom filter.
size | number of IBF buckets |
hash_num | number of buckets one element is hashed in |
Definition at line 80 of file ibf.c.
References InvertibleBloomFilter::count, GNUNET_assert, GNUNET_free, GNUNET_malloc_large, GNUNET_new, hash_num, InvertibleBloomFilter::hash_num, InvertibleBloomFilter::key_hash_sum, InvertibleBloomFilter::key_sum, InvertibleBloomFilter::size, and size.
Referenced by handle_union_p2p_ibf(), prepare_ibf(), run(), and strata_estimator_create().
|
static |
Store unique bucket indices for the specified key in dst.
Definition at line 119 of file ibf.c.
References GNUNET_CRYPTO_crc32_n(), InvertibleBloomFilter::hash_num, key, and InvertibleBloomFilter::size.
Referenced by ibf_decode(), ibf_insert(), and ibf_remove().
|
static |
Definition at line 144 of file ibf.c.
References InvertibleBloomFilter::count, IBF_Count::count_val, InvertibleBloomFilter::hash_num, IBF_KEY_HASH_VAL, key, InvertibleBloomFilter::key_hash_sum, IBF_KeyHash::key_hash_val, InvertibleBloomFilter::key_sum, and IBF_Key::key_val.
Referenced by ibf_decode(), ibf_insert(), and ibf_remove().
void ibf_insert | ( | struct InvertibleBloomFilter * | ibf, |
struct IBF_Key | key | ||
) |
Insert a key into an IBF.
ibf | the IBF |
key | the element's hash code |
Definition at line 168 of file ibf.c.
References GNUNET_assert, InvertibleBloomFilter::hash_num, ibf_get_indices(), ibf_insert_into(), key, and InvertibleBloomFilter::size.
Referenced by insert_iterator(), prepare_ibf_iterator(), and strata_estimator_insert().
void ibf_remove | ( | struct InvertibleBloomFilter * | ibf, |
struct IBF_Key | key | ||
) |
Remove a key from an IBF.
ibf | the IBF |
key | the element's hash code |
Definition at line 185 of file ibf.c.
References GNUNET_assert, InvertibleBloomFilter::hash_num, ibf_get_indices(), ibf_insert_into(), key, and InvertibleBloomFilter::size.
Referenced by strata_estimator_remove().
|
static |
Test is the IBF is empty, i.e.
all counts, keys and key hashes are zero.
Definition at line 199 of file ibf.c.
References InvertibleBloomFilter::count, IBF_Count::count_val, GNUNET_NO, GNUNET_YES, InvertibleBloomFilter::key_hash_sum, IBF_KeyHash::key_hash_val, InvertibleBloomFilter::key_sum, IBF_Key::key_val, and InvertibleBloomFilter::size.
Referenced by ibf_decode().
int ibf_decode | ( | struct InvertibleBloomFilter * | ibf, |
int * | ret_side, | ||
struct IBF_Key * | ret_id | ||
) |
Decode and remove an element from the IBF, if possible.
ibf | the invertible bloom filter to decode |
ret_side | sign of the cell's count where the decoded element came from. A negative sign indicates that the element was recovered resides in an IBF that was previously subtracted from. |
ret_id | receives the hash code of the decoded element, if successful |
Definition at line 229 of file ibf.c.
References InvertibleBloomFilter::count, IBF_Count::count_val, GNUNET_assert, GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, InvertibleBloomFilter::hash_num, ibf_get_indices(), ibf_insert_into(), ibf_is_empty(), IBF_KEY_HASH_VAL, InvertibleBloomFilter::key_hash_sum, IBF_KeyHash::key_hash_val, InvertibleBloomFilter::key_sum, and InvertibleBloomFilter::size.
Referenced by decode_and_send(), run(), and strata_estimator_difference().
void ibf_write_slice | ( | const struct InvertibleBloomFilter * | ibf, |
uint32_t | start, | ||
uint32_t | count, | ||
void * | buf | ||
) |
Write buckets from an ibf to a buffer.
Exactly (IBF_BUCKET_SIZE*ibf->size) bytes are written to buf.
ibf | the ibf to write |
start | with which bucket to start |
count | how many buckets to write |
buf | buffer to write the data to |
Definition at line 291 of file ibf.c.
References InvertibleBloomFilter::count, GNUNET_assert, GNUNET_memcpy, InvertibleBloomFilter::key_hash_sum, InvertibleBloomFilter::key_sum, size, and start.
Referenced by send_ibf(), and strata_estimator_write().
void ibf_read_slice | ( | const void * | buf, |
uint32_t | start, | ||
uint32_t | count, | ||
struct InvertibleBloomFilter * | ibf | ||
) |
Read buckets from a buffer into an ibf.
buf | pointer to the buffer to read from |
start | which bucket to start at |
count | how many buckets to read |
ibf | the ibf to read from |
Definition at line 324 of file ibf.c.
References InvertibleBloomFilter::count, GNUNET_assert, GNUNET_memcpy, InvertibleBloomFilter::key_hash_sum, InvertibleBloomFilter::key_sum, size, and start.
Referenced by handle_union_p2p_ibf(), and strata_estimator_read().
void ibf_subtract | ( | struct InvertibleBloomFilter * | ibf1, |
const struct InvertibleBloomFilter * | ibf2 | ||
) |
Subtract ibf2 from ibf1, storing the result in ibf1.
The two IBF's must have the same parameters size and hash_num.
ibf1 | IBF that is subtracted from |
ibf2 | IBF that will be subtracted from ibf1 |
Definition at line 357 of file ibf.c.
References InvertibleBloomFilter::count, IBF_Count::count_val, GNUNET_assert, InvertibleBloomFilter::hash_num, InvertibleBloomFilter::key_hash_sum, IBF_KeyHash::key_hash_val, InvertibleBloomFilter::key_sum, IBF_Key::key_val, and InvertibleBloomFilter::size.
Referenced by decode_and_send(), run(), and strata_estimator_difference().
struct InvertibleBloomFilter * ibf_dup | ( | const struct InvertibleBloomFilter * | ibf | ) |
Create a copy of an IBF, the copy has to be destroyed properly.
ibf | the IBF to copy |
Definition at line 380 of file ibf.c.
References InvertibleBloomFilter::count, GNUNET_malloc, GNUNET_memdup, InvertibleBloomFilter::hash_num, InvertibleBloomFilter::key_hash_sum, InvertibleBloomFilter::key_sum, and InvertibleBloomFilter::size.
Referenced by decode_and_send(), strata_estimator_difference(), and strata_estimator_dup().
void ibf_destroy | ( | struct InvertibleBloomFilter * | ibf | ) |
Destroy all resources associated with the invertible bloom filter.
No more ibf_*-functions may be called on ibf after calling destroy.
ibf | the intertible bloom filter to destroy |
Definition at line 404 of file ibf.c.
References InvertibleBloomFilter::count, GNUNET_free, InvertibleBloomFilter::key_hash_sum, and InvertibleBloomFilter::key_sum.
Referenced by _GSS_operation_destroy(), decode_and_send(), prepare_ibf(), strata_estimator_create(), strata_estimator_destroy(), strata_estimator_difference(), and union_op_cancel().