26 #ifndef HYPERTABLE_TCLHASH_H
27 #define HYPERTABLE_TCLHASH_H
48 ret += (ret << 3) + (unsigned)*s;
61 inline size_t tcl_hash(
const void *data,
size_t len,
size_t seed) {
63 const uint8_t *dp = (uint8_t *)data, *end = dp + len;
65 for (; dp < end; ++dp)
66 ret += (ret << 3) + *dp;
71 #define HT_TCLHASH_DO2(p, i) \
72 ret += (ret << 3) + p[i]; ret += (ret << 3) + p[i+1]
74 #define HT_TCLHASH_DO4(p, i) HT_TCLHASH_DO2(p, i); HT_TCLHASH_DO2(p, i+2);
75 #define HT_TCLHASH_DO8(p, i) HT_TCLHASH_DO4(p, i); HT_TCLHASH_DO4(p, i+4);
85 inline size_t tcl_hash2(
const void *data,
size_t len,
size_t seed) {
87 const uint8_t *dp = (uint8_t *)data;
96 ret += (ret << 3) + *dp++;
111 size_t operator()(
const void *start,
size_t len,
size_t seed = 0)
const {
117 return tcl_hash(s.c_str(), s.length(), 0);
133 size_t operator()(
const void *start,
size_t len,
size_t seed = 0)
const {
139 return tcl_hash2(s.c_str(), s.length(), 0);
152 #endif // HYPERTABLE_TCLHASH_H
#define HT_TCLHASH_DO8(p, i)
std::string String
A String is simply a typedef to std::string.
Helper structure using overloaded operator() to calculate the Tcl hashes of various input types (usin...
size_t operator()(const void *start, size_t len, size_t seed=0) const
Returns hash of a memory buffer with an optional seed.
size_t operator()(const String &s) const
Returns hash of a String.
size_t operator()(const String &s) const
Returns hash of a String.
Helper structure using overloaded operator() to calculate the Tcl hashes of various input types...
size_t operator()(const char *s) const
Returns hash of a null-terminated c-String.
size_t operator()(const char *s) const
Returns hash of a null-terminated c-String.
size_t tcl_hash(const char *s)
The Tcl hash by John Ousterhout for null-terminated c-strings, preferably alpha-numeric characters on...
A String class based on std::string.
size_t tcl_hash2(const void *data, size_t len, size_t seed)
Unrolled Tcl hash, up to 20% faster for longer (> 8 bytes) strings.
size_t operator()(const void *start, size_t len, size_t seed=0) const
Returns hash of a memory buffer with an optional seed.