testing hash
This commit is contained in:
Submodule
+1
Submodule hash_testing/src/cityhash added at f5dc54147f
@@ -0,0 +1,46 @@
|
||||
#include "hash.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#define JOAAT_SEED 0x9e3779b9u
|
||||
|
||||
uint32_t joaat_hash_bytes(const void *data, size_t len)
|
||||
{
|
||||
uint32_t hash = JOAAT_SEED;
|
||||
const unsigned char *p = (const unsigned char *)data;
|
||||
|
||||
while (len-- > 0) {
|
||||
hash += *p++;
|
||||
hash += (hash << 10);
|
||||
hash ^= (hash >> 6);
|
||||
}
|
||||
|
||||
hash += (hash << 3);
|
||||
hash ^= (hash >> 11);
|
||||
hash += (hash << 15);
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
uint32_t joaat_hash(const char *str)
|
||||
{
|
||||
uint32_t hash = JOAAT_SEED;
|
||||
const unsigned char *p = (const unsigned char *)str;
|
||||
|
||||
while (*p) {
|
||||
hash += *p++;
|
||||
hash += (hash << 10);
|
||||
hash ^= (hash >> 6);
|
||||
}
|
||||
|
||||
hash += (hash << 3);
|
||||
hash ^= (hash >> 11);
|
||||
hash += (hash << 15);
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
unsigned int hash(const char *str)
|
||||
{
|
||||
return (unsigned int)joaat_hash(str);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef ARSV_JOAAT_HASH_H
|
||||
#define ARSV_JOAAT_HASH_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
uint32_t joaat_hash(const char *str);
|
||||
uint32_t joaat_hash_bytes(const void *data, size_t len);
|
||||
|
||||
/* Compatibility wrapper matching the original set.c function name. */
|
||||
unsigned int hash(const char *str);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ARSV_JOAAT_HASH_H */
|
||||
Submodule
+1
Submodule hash_testing/src/xxHash added at e573d4d2aa
Reference in New Issue
Block a user