Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the inital work on making this parallel.
- Loading branch information
1 parent
6d68769
commit 2e6084e
Showing
1,042 changed files
with
127,202 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Author: Chris Wailes <chris.wailes@gmail.com> | ||
* Project: Chris's Awesome Standard Library | ||
* Description: A simple Bloom Filter implementation that was initially | ||
taken from here: http://en.literateprograms.org/Bloom_filter_%28C%29 | ||
*/ | ||
|
||
// Standard Includes | ||
#include <limits.h> | ||
#include <stdarg.h> | ||
#include <string.h> | ||
#include <sys/types.h> | ||
|
||
// Project Includes | ||
#include "bloom.h" | ||
#include "util.h" | ||
|
||
// Macros | ||
#define SETBIT(a, n) (a[n / CHAR_BIT] |= (1 << (n % CHAR_BIT))) | ||
#define GETBIT(a, n) (a[n / CHAR_BIT] & (1 << (n % CHAR_BIT))) | ||
|
||
#define BYTES_FOR_BITS(bits) ((bits + CHAR_BIT - 1) / CHAR_BIT) | ||
|
||
// Global Variables | ||
|
||
// Functions | ||
|
||
/* | ||
* Size represents the length of the filter in BITS. | ||
*/ | ||
bloom_t* bloom_create(size_t size, uint nfuncs, ...) { | ||
bloom_t* bloom; | ||
va_list arg_list; | ||
|
||
if ((bloom = bloom_new()) == NULL) { | ||
return NULL; | ||
} | ||
|
||
if (!bloom_init(bloom, size, nfuncs, arg_list)) { | ||
free(bloom); | ||
return NULL; | ||
} | ||
|
||
return bloom; | ||
} | ||
|
||
void bloom_destroy(bloom_t* bloom) { | ||
free(bloom->bits); | ||
free(bloom->funcs); | ||
free(bloom); | ||
} | ||
|
||
/* | ||
* Size represents the length of the filter in BITS. | ||
*/ | ||
bool bloom_init(bloom_t* bloom, size_t size, uint nfuncs, ...) { | ||
va_list arg_list; | ||
|
||
if ((bloom->bits = (unsigned char*) calloc(BYTES_FOR_BITS(size), sizeof(char))) == NULL) { | ||
return FALSE; | ||
} | ||
|
||
if ((bloom->funcs = (bloomhash_t*) calloc(nfuncs, sizeof(bloomhash_t))) == NULL) { | ||
free(bloom->bits); | ||
return FALSE; | ||
} | ||
|
||
bloom->bits_size = size; | ||
bloom->nfuncs = nfuncs; | ||
|
||
va_start(arg_list, nfuncs); | ||
while (nfuncs-- > 0) { | ||
bloom->funcs[nfuncs] = va_arg(arg_list, bloomhash_t); | ||
} | ||
va_end(arg_list); | ||
|
||
return TRUE; | ||
} | ||
|
||
bloom_t* bloom_new(void) { | ||
return (bloom_t*) malloc(sizeof(bloom_t)); | ||
} | ||
|
||
void bloom_add(bloom_t* bloom, const unsigned char* data, uint length) { | ||
uint index; | ||
|
||
for (index = bloom->nfuncs; index-- > 0;) { | ||
SETBIT(bloom->bits, bloom->funcs[index](data, length) % bloom->bits_size); | ||
} | ||
} | ||
|
||
bool bloom_check(bloom_t* bloom, const unsigned char* data, uint length) { | ||
uint index; | ||
|
||
for (index = bloom->nfuncs; index-- > 0;) { | ||
if(!(GETBIT(bloom->bits, bloom->funcs[index](data, length) % bloom->bits_size))) return FALSE; | ||
} | ||
|
||
return TRUE; | ||
} | ||
|
||
#include <stdio.h> | ||
|
||
void bloom_reset(bloom_t* bloom) { | ||
memset(bloom->bits, 0, BYTES_FOR_BITS(bloom->bits_size)); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Author: Chris Wailes <chris.wailes@gmail.com> | ||
* Project: Chris's Awesome Standard Library | ||
* Description: Declarations for a simple Bloom Filter implementation that | ||
was initially taken from here: http://en.literateprograms.org/Bloom_filter_%28C%29 | ||
*/ | ||
|
||
#ifndef BLOOM_H | ||
#define BLOOM_H | ||
|
||
// Standard Includes | ||
#include <stdlib.h> | ||
#include <sys/types.h> | ||
|
||
// Project Includes | ||
#include "hashes.h" | ||
#include "util.h" | ||
|
||
// Macros | ||
|
||
// 0.25MiB == 2^18 bytes == 2097152 bits | ||
#define BLOOM_SIZE_SMALL 2097152 | ||
|
||
// 0.50MiB == 2^19 bytes == 4194304 bits | ||
#define BLOOM_SIZE_MEDIUM 4194304 | ||
|
||
// 1.00MiB == 2^20 bytes == 8388608 bits | ||
#define BLOOM_SIZE_LARGE 8388608 | ||
|
||
#define DEFAULT_BLOOM_FILTER bloom_create(BLOOM_SIZE_MEDIUM, 3, bernstein_hash, sax_hash, sdbm_hash) | ||
|
||
// Types | ||
|
||
typedef unsigned int (*bloomhash_t)(const unsigned char*, uint); | ||
|
||
typedef struct { | ||
size_t bits_size; | ||
unsigned char* bits; | ||
|
||
uint nfuncs; | ||
bloomhash_t* funcs; | ||
} bloom_t; | ||
|
||
// Functions | ||
|
||
bloom_t* bloom_create(size_t size, uint nfuncs, ...); | ||
void bloom_destroy(bloom_t* bloom); | ||
bool bloom_init(bloom_t* bloom, size_t size, uint nfuncs, ...); | ||
bloom_t* bloom_new(void); | ||
|
||
void bloom_add(bloom_t* bloom, const unsigned char* data, uint length); | ||
bool bloom_check(bloom_t* bloom, const unsigned char* data, uint length); | ||
void bloom_reset(bloom_t* bloom); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Author: Chris Wailes <chris.wailes@gmail.com> | ||
* Project: Chris's Awesome Standard Library | ||
* Description: Simple, non-cryptographically secure, hashes. | ||
*/ | ||
|
||
// Standard Includes | ||
#include <sys/types.h> | ||
|
||
// Project Includes | ||
|
||
// Macros | ||
|
||
// Global Variables | ||
|
||
// Functions | ||
|
||
uint bernstein_hash(const unsigned char* data, uint length) { | ||
uint hash = 0; | ||
|
||
while (length-- > 0) { | ||
hash = 33 * hash + *data++; | ||
} | ||
|
||
return hash; | ||
} | ||
|
||
uint sax_hash(const unsigned char* data, uint length) { | ||
uint hash = 0; | ||
|
||
while (length-- > 0) { | ||
hash ^= (hash << 5) + (hash >> 2) + (unsigned char)*data++; | ||
} | ||
|
||
return hash; | ||
} | ||
|
||
uint sdbm_hash(const unsigned char* data, uint length) { | ||
uint hash = 0; | ||
|
||
while (length-- > 0) { | ||
hash = (unsigned char)*data++ + (hash << 6) + (hash << 16) - hash; | ||
} | ||
|
||
return hash; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Author: Chris Wailes <chris.wailes@gmail.com> | ||
* Project: Chris's Awesome Standard Library | ||
* Description: Simple, non-cryptographically secure, hashes. | ||
*/ | ||
|
||
#ifndef HASHES_H | ||
#define HASHES_H | ||
|
||
// Standard Includes | ||
#include <sys/types.h> | ||
|
||
// Project Includes | ||
|
||
// Macros | ||
|
||
// Types | ||
|
||
// Functions | ||
|
||
uint bernstein_hash(const unsigned char* data, uint length); | ||
uint sax_hash(const unsigned char* data, uint length); | ||
uint sdbm_hash(const unsigned char* data, uint length); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.