1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

sys: use typedef for struct bloom_t

`bloom_t` is defined as a struct.
`_t` can mislead the user to think of bloom_t
as a typedef (see our coding conventions) instead of a struct.
Thus, I modified `struct bloom_t` to be a *typedefed* struct.

Another solution would be to rename bloom_t to sth. like bloom_s
everywhere and use `struct bloom_s` instead of `bloom_t`.
This commit is contained in:
Cenk Gündoğan 2014-09-17 19:54:40 +02:00
parent 429218e3b4
commit 0a4ea07daa
4 changed files with 15 additions and 15 deletions

View File

@ -23,14 +23,14 @@
#define GETBIT(a,n) (a[n/CHAR_BIT] & (1<<(n%CHAR_BIT))) #define GETBIT(a,n) (a[n/CHAR_BIT] & (1<<(n%CHAR_BIT)))
#define ROUND(size) ((size + CHAR_BIT - 1) / CHAR_BIT) #define ROUND(size) ((size + CHAR_BIT - 1) / CHAR_BIT)
struct bloom_t *bloom_new(size_t size, size_t num_hashes, ...) bloom_t *bloom_new(size_t size, size_t num_hashes, ...)
{ {
struct bloom_t *bloom; bloom_t *bloom;
va_list hashes; va_list hashes;
size_t n; size_t n;
/* Allocate Bloom filter container */ /* Allocate Bloom filter container */
if (!(bloom = malloc(sizeof(struct bloom_t)))) { if (!(bloom = malloc(sizeof(bloom_t)))) {
return NULL; return NULL;
} }
@ -66,14 +66,14 @@ struct bloom_t *bloom_new(size_t size, size_t num_hashes, ...)
return bloom; return bloom;
} }
void bloom_del(struct bloom_t *bloom) void bloom_del(bloom_t *bloom)
{ {
free(bloom->a); free(bloom->a);
free(bloom->hash); free(bloom->hash);
free(bloom); free(bloom);
} }
void bloom_add(struct bloom_t *bloom, const uint8_t *buf, size_t len) void bloom_add(bloom_t *bloom, const uint8_t *buf, size_t len)
{ {
for (size_t n = 0; n < bloom->k; n++) { for (size_t n = 0; n < bloom->k; n++) {
uint32_t hash = bloom->hash[n](buf, len); uint32_t hash = bloom->hash[n](buf, len);
@ -81,7 +81,7 @@ void bloom_add(struct bloom_t *bloom, const uint8_t *buf, size_t len)
} }
} }
bool bloom_check(struct bloom_t *bloom, const uint8_t *buf, size_t len) bool bloom_check(bloom_t *bloom, const uint8_t *buf, size_t len)
{ {
for (size_t n = 0; n < bloom->k; n++) { for (size_t n = 0; n < bloom->k; n++) {
uint32_t hash = bloom->hash[n](buf, len); uint32_t hash = bloom->hash[n](buf, len);

View File

@ -125,14 +125,14 @@
typedef uint32_t (*hashfp_t)(const uint8_t *, int len); typedef uint32_t (*hashfp_t)(const uint8_t *, int len);
/** /**
* struct bloom_t bloom filter object * bloom_t bloom filter object
*/ */
struct bloom_t { typedef struct {
size_t m; size_t m;
size_t k; size_t k;
uint8_t *a; uint8_t *a;
hashfp_t *hash; hashfp_t *hash;
}; } bloom_t;
/** /**
* bloom_new Allocate and return a pointer to a new Bloom filter. * bloom_new Allocate and return a pointer to a new Bloom filter.
@ -146,7 +146,7 @@ struct bloom_t {
* @return An allocated bloom filter * @return An allocated bloom filter
* *
*/ */
struct bloom_t *bloom_new(size_t size, size_t num_hashes, ...); bloom_t *bloom_new(size_t size, size_t num_hashes, ...);
/** /**
* bloom_del Delete a Bloom filter. * bloom_del Delete a Bloom filter.
@ -155,7 +155,7 @@ struct bloom_t *bloom_new(size_t size, size_t num_hashes, ...);
* @return nothing * @return nothing
* *
*/ */
void bloom_del(struct bloom_t *bloom); void bloom_del(bloom_t *bloom);
/** /**
* bloom_add Add a string to a Bloom filter. * bloom_add Add a string to a Bloom filter.
@ -168,7 +168,7 @@ void bloom_del(struct bloom_t *bloom);
* @return nothing * @return nothing
* *
*/ */
void bloom_add(struct bloom_t *bloom, const uint8_t *buf, size_t len); void bloom_add(bloom_t *bloom, const uint8_t *buf, size_t len);
/** /**
* bloom_check Determine if a string is in the Bloom filter. * bloom_check Determine if a string is in the Bloom filter.
@ -205,7 +205,7 @@ void bloom_add(struct bloom_t *bloom, const uint8_t *buf, size_t len);
* @return true if string is may be in the filter * @return true if string is may be in the filter
* *
*/ */
bool bloom_check(struct bloom_t *bloom, const uint8_t *buf, size_t len); bool bloom_check(bloom_t *bloom, const uint8_t *buf, size_t len);
/** @} */ /** @} */
#endif /* _BLOOM_FILTER_H */ #endif /* _BLOOM_FILTER_H */

View File

@ -28,7 +28,7 @@
int main(void) int main(void)
{ {
struct bloom_t *bloom = bloom_new(1 << 7, 6, fnv_hash, sax_hash, sdbm_hash, bloom_t *bloom = bloom_new(1 << 7, 6, fnv_hash, sax_hash, sdbm_hash,
djb2_hash, kr_hash, dek_hash, rotating_hash, one_at_a_time_hash); djb2_hash, kr_hash, dek_hash, rotating_hash, one_at_a_time_hash);
printf("Testing Bloom filter.\n\n"); printf("Testing Bloom filter.\n\n");

View File

@ -50,7 +50,7 @@ int main(void)
{ {
hwtimer_init(); hwtimer_init();
struct bloom_t *bloom = bloom_new(1 << 12, 8, fnv_hash, sax_hash, sdbm_hash, bloom_t *bloom = bloom_new(1 << 12, 8, fnv_hash, sax_hash, sdbm_hash,
djb2_hash, kr_hash, dek_hash, rotating_hash, one_at_a_time_hash); djb2_hash, kr_hash, dek_hash, rotating_hash, one_at_a_time_hash);
printf("Testing Bloom filter.\n\n"); printf("Testing Bloom filter.\n\n");