Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add xxHash hashing algorithm #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"src/mmapbitarray.c",
"src/bloomfilter.c",
"src/md5.c",
"src/xxhash.c",
"src/primetester.c",
"src/MurmurHash3.c",
]
Expand Down
42 changes: 36 additions & 6 deletions src/bloomfilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@

#include "bloomfilter.h"

/* Available hashing algorithms */
#define HASHALG_SHA512 1
#define HASHALG_SUPERFAST 2
#define HASHALG_MURMURHASH3 3
#define HASHALG_XXHASH32 4
#define HASHALG_XXHASH64 5

/* We're using xxHash */
#define HASHING_ALGORITHM HASHALG_XXHASH64


BloomFilter *bloomfilter_Create_Malloc(size_t max_num_elem, double error_rate,
BTYPE num_bits, int *hash_seeds, int num_hashes)
{
Expand Down Expand Up @@ -154,11 +165,9 @@ BTYPE _hash_long(uint32_t hash_seed, Key * key) {
return _hash_char(hash_seed, &newKey);
}

/*
CODE TO USE SHA512..
#if HASHING_ALGORITHM == HASHALG_SHA512
#include <openssl/evp.h>
uint32_t _hash_char(uint32_t hash_seed, Key * key) {
BTYPE _hash_char(uint32_t hash_seed, Key * key) {
EVP_MD_CTX ctx;
unsigned char result_buffer[64];

Expand All @@ -171,17 +180,38 @@ uint32_t _hash_char(uint32_t hash_seed, Key * key) {
EVP_MD_CTX_cleanup(&ctx);
return *(uint32_t *)result_buffer;
}
*/
#endif

/* Code for MurmurHash3 */
#if HASHING_ALGORITHM == HASHALG_MURMURHASH3
#include "MurmurHash3.h"
BTYPE _hash_char(uint32_t hash_seed, Key * key) {
BTYPE hashed_pieces[2];
MurmurHash3_x64_128((const void *)key->shash, (int)key->nhash,
hash_seed, &hashed_pieces);
return hashed_pieces[0] ^ hashed_pieces[1];
}
#endif

#if HASHING_ALGORITHM == HASHALG_SUPERFAST
#include "superfast.h"
BTYPE _hash_char(uint32_t hash_seed, Key * key) {
return SuperFastHash(key->shash, key->nhash, hash_seed);
}
#endif

#if HASHING_ALGORITHM == HASHALG_XXHASH32
#include "xxhash.h"
BTYPE _hash_char(uint32_t hash_seed, Key * key) {
return XXH32(key->shash, key->nhash, hash_seed);
}
#endif

#if HASHING_ALGORITHM == HASHALG_XXHASH64
#include "xxhash.h"
BTYPE _hash_char(uint32_t hash_seed, Key * key) {
return XXH64(key->shash, key->nhash, hash_seed);
}
#endif

#if 0
int main(int argc, char **argv)
Expand Down
Loading