18 #ifndef __ehash_h_included 19 #define __ehash_h_included 22 #include <bits/hash_bytes.h> 43 static ULong
getHash(cpChar val, ULong len);
48 static ULong
getHash(cpUChar val, ULong len);
51 static ULong m_crcTable[256];
77 Key(
const Key &k) { assign(k.data_,
sizeof(k.data_)); }
81 Key(cpUChar k,
const size_t len) { assign(k,len); }
85 operator cpUChar()
const {
return data_; }
88 cpUChar
data()
const {
return data_; }
97 for (; i<min(len,
sizeof(data_)); i++)
99 for( ; i <
sizeof(data_); i++)
126 return getHash32(reinterpret_cast<cpUChar>(str.c_str()), str.length(), key);
133 static ULong
getHash32(cpChar val,
const size_t len,
const Key &key=key_)
135 return getHash32(reinterpret_cast<cpUChar>(val), len, key);
142 static ULong getHash32(cpUChar in,
const size_t inlen,
const Key &key=key_);
150 static Bool getHash32(cpUChar in,
const size_t inlen, pUChar out,
const size_t outlen,
const Key &key=key_);
156 static ULong
getHash32(cShort val,
const Key &key=key_) {
return getHash32(reinterpret_cast<cpUChar>(&val),
sizeof(val), key); }
157 static ULong
getHash32(cUShort val,
const Key &key=key_) {
return getHash32(reinterpret_cast<cpUChar>(&val),
sizeof(val), key); }
158 static ULong
getHash32(cLong val,
const Key &key=key_) {
return getHash32(reinterpret_cast<cpUChar>(&val),
sizeof(val), key); }
159 static ULong
getHash32(cULong val,
const Key &key=key_) {
return getHash32(reinterpret_cast<cpUChar>(&val),
sizeof(val), key); }
160 static ULong
getHash32(cLongLong val,
const Key &key=key_) {
return getHash32(reinterpret_cast<cpUChar>(&val),
sizeof(val), key); }
161 static ULong
getHash32(cULongLong val,
const Key &key=key_) {
return getHash32(reinterpret_cast<cpUChar>(&val),
sizeof(val), key); }
162 static ULong
getHash32(cFloat val,
const Key &key=key_) {
return getHash32(reinterpret_cast<cpUChar>(&val),
sizeof(val), key); }
163 static ULong
getHash32(cDouble val,
const Key &key=key_) {
return getHash32(reinterpret_cast<cpUChar>(&val),
sizeof(val), key); }
172 return getHash64(reinterpret_cast<cpUChar>(str.c_str()), str.length(), key);
179 static ULongLong
getHash64(cpChar val,
const size_t len,
const Key &key=key_)
181 return getHash64(reinterpret_cast<cpUChar>(val), len, key);
188 static ULongLong getHash64(cpUChar in,
const size_t inlen,
const Key &key=key_);
196 static Bool getHash64(cpUChar in,
size_t inlen, pUChar out,
const size_t outlen,
const Key &key=key_);
201 static ULongLong
getHash64(cShort val,
const Key &key=key_) {
return getHash64(reinterpret_cast<cpUChar>(&val),
sizeof(val), key); }
202 static ULongLong
getHash64(cUShort val,
const Key &key=key_) {
return getHash64(reinterpret_cast<cpUChar>(&val),
sizeof(val), key); }
203 static ULongLong
getHash64(cLong val,
const Key &key=key_) {
return getHash64(reinterpret_cast<cpUChar>(&val),
sizeof(val), key); }
204 static ULongLong
getHash64(cULong val,
const Key &key=key_) {
return getHash64(reinterpret_cast<cpUChar>(&val),
sizeof(val), key); }
205 static ULongLong
getHash64(cLongLong val,
const Key &key=key_) {
return getHash64(reinterpret_cast<cpUChar>(&val),
sizeof(val), key); }
206 static ULongLong
getHash64(cULongLong val,
const Key &key=key_) {
return getHash64(reinterpret_cast<cpUChar>(&val),
sizeof(val), key); }
207 static ULongLong
getHash64(cFloat val,
const Key &key=key_) {
return getHash64(reinterpret_cast<cpUChar>(&val),
sizeof(val), key); }
208 static ULongLong
getHash64(cDouble val,
const Key &key=key_) {
return getHash64(reinterpret_cast<cpUChar>(&val),
sizeof(val), key); }
219 return getHash128(reinterpret_cast<cpUChar>(str.c_str()), str.length(), out, outlen, key);
228 static Bool
getHash128(cpChar val,
size_t len, pUChar out,
const size_t outlen,
const Key &key=key_)
230 return getHash128(reinterpret_cast<cpUChar>(val), len, out, outlen, key);
239 static Bool getHash128(cpUChar in,
size_t inlen, pUChar out,
const size_t outlen,
const Key &key=key_);
247 static Bool
getHash128(cShort val, pUChar out,
const size_t outlen,
const Key &key=key_) {
return getHash128(reinterpret_cast<cpUChar>(&val),
sizeof(val), out, outlen, key); }
248 static Bool
getHash128(cUShort val, pUChar out,
const size_t outlen,
const Key &key=key_) {
return getHash128(reinterpret_cast<cpUChar>(&val),
sizeof(val), out, outlen, key); }
249 static Bool
getHash128(cLong val, pUChar out,
const size_t outlen,
const Key &key=key_) {
return getHash128(reinterpret_cast<cpUChar>(&val),
sizeof(val), out, outlen, key); }
250 static Bool
getHash128(cULong val, pUChar out,
const size_t outlen,
const Key &key=key_) {
return getHash128(reinterpret_cast<cpUChar>(&val),
sizeof(val), out, outlen, key); }
251 static Bool
getHash128(cLongLong val, pUChar out,
const size_t outlen,
const Key &key=key_) {
return getHash128(reinterpret_cast<cpUChar>(&val),
sizeof(val), out, outlen, key); }
252 static Bool
getHash128(cULongLong val, pUChar out,
const size_t outlen,
const Key &key=key_) {
return getHash128(reinterpret_cast<cpUChar>(&val),
sizeof(val), out, outlen, key); }
253 static Bool
getHash128(cFloat val, pUChar out,
const size_t outlen,
const Key &key=key_) {
return getHash128(reinterpret_cast<cpUChar>(&val),
sizeof(val), out, outlen, key); }
254 static Bool
getHash128(cDouble val, pUChar out,
const size_t outlen,
const Key &key=key_) {
return getHash128(reinterpret_cast<cpUChar>(&val),
sizeof(val), out, outlen, key); }
258 static Bool getFullHash(cpUChar in,
size_t inlen, cpUChar k, pUChar out,
const size_t outlen);
259 static Bool getHalfHash(cpUChar in,
size_t inlen, cpUChar k, pUChar out,
const size_t outlen);
273 static size_t getHash(cChar val,
size_t seed=0xc70f6907UL) {
return _Hash_bytes(&val,
sizeof(val),seed); }
274 static size_t getHash(cUChar val,
size_t seed=0xc70f6907UL) {
return _Hash_bytes(&val,
sizeof(val),seed); }
275 static size_t getHash(cShort val,
size_t seed=0xc70f6907UL) {
return _Hash_bytes(&val,
sizeof(val),seed); }
276 static size_t getHash(cUShort val,
size_t seed=0xc70f6907UL) {
return _Hash_bytes(&val,
sizeof(val),seed); }
277 static size_t getHash(cLong val,
size_t seed=0xc70f6907UL) {
return _Hash_bytes(&val,
sizeof(val),seed); }
278 static size_t getHash(cULong val,
size_t seed=0xc70f6907UL) {
return _Hash_bytes(&val,
sizeof(val),seed); }
279 static size_t getHash(cLongLong val,
size_t seed=0xc70f6907UL) {
return _Hash_bytes(&val,
sizeof(val),seed); }
280 static size_t getHash(cULongLong val,
size_t seed=0xc70f6907UL) {
return _Hash_bytes(&val,
sizeof(val),seed); }
281 static size_t getHash(cFloat val,
size_t seed=0xc70f6907UL) {
return _Hash_bytes(&val,
sizeof(val),seed); }
282 static size_t getHash(cDouble val,
size_t seed=0xc70f6907UL) {
return _Hash_bytes(&val,
sizeof(val),seed); }
283 static size_t getHash(
const EString &val,
size_t seed=0xc70f6907UL) {
return _Hash_bytes(val.c_str(),val.size(),seed); }
292 static size_t getHash(cpChar val,
size_t len,
size_t seed=0xc70f6907UL) {
return _Hash_bytes(val,len,seed); }
293 static size_t getHash(cpUChar val,
size_t len,
size_t seed=0xc70f6907UL) {
return _Hash_bytes(val,len,seed); }
302 return rotateLeft(circularAdd(h1,h2), 19) ^ circularSubtract(h1,h2);
306 static size_t rotateLeft(
const size_t val,
const size_t bits)
308 return (
size_t)((val << bits) | (val >> (64 - bits)));
311 static size_t circularAdd(
size_t val1,
size_t val2)
313 size_t result = val1 + val2;
314 return result + (result < val1);
317 static size_t circularSubtract(
size_t val1,
size_t val2)
319 size_t result = val1 - val2;
320 return result - (result > val1);
324 #endif // #define __ehash_h_included static size_t getHash(const EString &val, size_t seed=0xc70f6907UL)
Definition: ehash.h:283
Encapsulates and extends a std::string object.
static ULongLong getHash64(cLongLong val, const Key &key=key_)
Definition: ehash.h:205
static size_t getHash(cDouble val, size_t seed=0xc70f6907UL)
Definition: ehash.h:282
Macros for various standard C library functions and standard includes.
Represents a key to be used when calculating a hash value.
Definition: ehash.h:70
Key & assign(cpUChar k, const size_t len)
Assigns a new key value.
Definition: ehash.h:94
static ULongLong getHash64(cULong val, const Key &key=key_)
Definition: ehash.h:204
Calcuates a 64-bit murmur hash for the specified value.
Definition: ehash.h:265
static ULong getHash32(cFloat val, const Key &key=key_)
Definition: ehash.h:162
static Bool getHash128(cpChar val, size_t len, pUChar out, const size_t outlen, const Key &key=key_)
Calculates the 128-bit hash associated with the character buffer.
Definition: ehash.h:228
static ULong getHash32(cShort val, const Key &key=key_)
Returns the 32-bit hash associated with the unsigned character buffer.
Definition: ehash.h:156
static Bool getHash128(cDouble val, pUChar out, const size_t outlen, const Key &key=key_)
Definition: ehash.h:254
static size_t getHash(cpChar val, size_t len, size_t seed=0xc70f6907UL)
Calculates a 64-bit murmur hash for the value.
Definition: ehash.h:292
cpUChar data() const
Data extractor.
Definition: ehash.h:88
Calcuates a 32-bit hash value for the specified string or array of characters.
Definition: ehash.h:32
static ULongLong getHash64(cFloat val, const Key &key=key_)
Definition: ehash.h:207
static Key & setKey(cpUChar val, const size_t len)
Assigns a new default key value.
Definition: ehash.h:115
static const Key & key()
Retrieves the default key.
Definition: ehash.h:118
static ULong getHash32(EString &str, const Key &key=key_)
Returns the 32-bit hash associated with the string.
Definition: ehash.h:124
static Bool getHash128(cULong val, pUChar out, const size_t outlen, const Key &key=key_)
Definition: ehash.h:250
static size_t getHash(cpUChar val, size_t len, size_t seed=0xc70f6907UL)
Definition: ehash.h:293
static ULong getHash(EString &str)
Returns the 32-bit hash value for the specified string.
Definition: ehash.cpp:24
static ULongLong getHash64(cpChar val, const size_t len, const Key &key=key_)
Returns the 64-bit hash associated with the character buffer.
Definition: ehash.h:179
static ULongLong getHash64(cULongLong val, const Key &key=key_)
Definition: ehash.h:206
static size_t getHash(cLongLong val, size_t seed=0xc70f6907UL)
Definition: ehash.h:279
static ULong getHash32(cDouble val, const Key &key=key_)
Definition: ehash.h:163
static ULong getHash32(cpChar val, const size_t len, const Key &key=key_)
Returns the 32-bit hash associated with the character buffer.
Definition: ehash.h:133
Calculates a 32-bit, 64-bit or 128-bit hash value using the SipHash algorithm.
Definition: ehash.h:66
static ULong getHash32(cULong val, const Key &key=key_)
Definition: ehash.h:159
static size_t getHash(cULong val, size_t seed=0xc70f6907UL)
Definition: ehash.h:278
static Bool getHash128(cUShort val, pUChar out, const size_t outlen, const Key &key=key_)
Definition: ehash.h:248
Defines base class for exceptions and declaration helper macros.
static ULongLong getHash64(cUShort val, const Key &key=key_)
Definition: ehash.h:202
static size_t getHash(cULongLong val, size_t seed=0xc70f6907UL)
Definition: ehash.h:280
static ULongLong getHash64(EString &str, const Key &key=key_)
Returns the 64-bit hash associated with the string.
Definition: ehash.h:170
static size_t getHash(cShort val, size_t seed=0xc70f6907UL)
Definition: ehash.h:275
static Bool getHash128(EString &str, pUChar out, const size_t outlen, const Key &key=key_)
Calculates the 128-bit hash associated with the string.
Definition: ehash.h:217
static Bool getHash128(cFloat val, pUChar out, const size_t outlen, const Key &key=key_)
Definition: ehash.h:253
Key()
Class constructor.
Definition: ehash.h:74
static ULong getHash32(cLongLong val, const Key &key=key_)
Definition: ehash.h:160
DECLARE_ERROR(ESipHash24Error_InvalidKeyLength)
static ULongLong getHash64(cDouble val, const Key &key=key_)
Definition: ehash.h:208
static Bool getHash128(cShort val, pUChar out, const size_t outlen, const Key &key=key_)
Calculates the 128-bit hash associated with the unsigned character buffer.
Definition: ehash.h:247
static size_t combine(size_t h1, size_t h2)
Combines 2 64-bit hash values.
Definition: ehash.h:300
static size_t getHash(cLong val, size_t seed=0xc70f6907UL)
Definition: ehash.h:277
static ULongLong getHash64(cLong val, const Key &key=key_)
Definition: ehash.h:203
static Bool getHash128(cULongLong val, pUChar out, const size_t outlen, const Key &key=key_)
Definition: ehash.h:252
Key(cpUChar k, const size_t len)
Class constructor.
Definition: ehash.h:81
static Bool getHash128(cLongLong val, pUChar out, const size_t outlen, const Key &key=key_)
Definition: ehash.h:251
static Bool getHash128(cLong val, pUChar out, const size_t outlen, const Key &key=key_)
Definition: ehash.h:249
Key(const Key &k)
Copy constructor.
Definition: ehash.h:77
static Key & setKey(const Key &k)
Assigns a new default key value.
Definition: ehash.h:110
static size_t getHash(cChar val, size_t seed=0xc70f6907UL)
Calculates a 64-bit murmur hash for the value.
Definition: ehash.h:273
static ULong getHash32(cULongLong val, const Key &key=key_)
Definition: ehash.h:161
static ULong getHash32(cLong val, const Key &key=key_)
Definition: ehash.h:158
static ULongLong getHash64(cShort val, const Key &key=key_)
Returns the 64-bit hash associated with the unsigned character buffer.
Definition: ehash.h:201
static size_t getHash(cUChar val, size_t seed=0xc70f6907UL)
Definition: ehash.h:274
static size_t getHash(cFloat val, size_t seed=0xc70f6907UL)
Definition: ehash.h:281
static ULong getHash32(cUShort val, const Key &key=key_)
Definition: ehash.h:157
String class.
Definition: estring.h:31
static size_t getHash(cUShort val, size_t seed=0xc70f6907UL)
Definition: ehash.h:276