A generic set of hashing functions built around Google's cityhash.
More...
|
static uint128_t | turi::hash128 (const char *s, size_t len) |
|
static uint128_t | turi::hash128 (const std::string &s) |
|
static uint128_t | turi::hash128 (uint128_t v) |
|
template<typename T > |
static uint128_t | turi::hash128 (const T &v, typename std::enable_if< std::is_integral< T >::value &&sizeof(T)<=8 >::type *=0) |
|
static uint128_t | turi::hash128 (uint64_t v) |
|
uint128_t | turi::hash128 (const flexible_type &v) |
|
uint128_t | turi::hash128 (const std::vector< flexible_type > &v) |
|
static uint64_t | turi::hash64 (const char *s, size_t len) |
|
static uint64_t | turi::hash64 (const std::string &s) |
|
static uint64_t | turi::hash64 (uint64_t v1, uint64_t v2) |
|
static uint64_t | turi::hash64 (uint64_t v1, uint64_t v2, uint64_t v3) |
|
static uint64_t | turi::hash64 (uint128_t v) |
|
template<typename T > |
static uint64_t | turi::hash64 (const T &v, typename std::enable_if< std::is_integral< T >::value &&sizeof(T)<=8 >::type *=0) |
|
uint64_t | turi::hash64 (const flexible_type &v) |
|
uint64_t | turi::hash64 (const std::vector< flexible_type > &v) |
|
static uint128_t | turi::hash128_combine (uint128_t h1, uint128_t h2) |
|
template<typename T > |
static uint128_t | turi::hash128_update (uint128_t h, const T &v) |
|
static uint128_t | turi::hash128 (const std::vector< std::string > &v) |
|
static uint64_t | turi::hash64_combine (uint64_t h1, uint64_t h2) |
|
uint64_t | turi::hash64_proportion_cutoff (double proportion) |
|
template<typename T > |
static uint64_t | turi::hash64_update (uint64_t h1, const T &t) |
|
static uint64_t | turi::hash64 (const std::vector< std::string > &v) |
|
static uint32_t | turi::simple_random_mapping (size_t index, size_t seed) |
|
static uint64_t | turi::index_hash (uint64_t idx) |
|
static uint64_t | turi::reverse_index_hash (uint64_t idx) |
|
A generic set of hashing functions built around Google's cityhash.
CityHasher is a std::hash-style wrapper around CityHash. We encourage using CityHasher instead of the default std::hash if possible.
This is a template specialization of CityHasher for std::string.
◆ hash128() [1/8]
static uint128_t turi::hash128 |
( |
const char * |
s, |
|
|
size_t |
len |
|
) |
| |
|
inlinestatic |
Returns a 128 bit hash of a string using the city hash function. The hash is strong but not cryptographically secure.
- Parameters
-
s | char* pointer to data. |
len | Length of data to hash, in bytes. |
Definition at line 833 of file cityhash_tc.hpp.
◆ hash128() [2/8]
static uint128_t turi::hash128 |
( |
const std::string & |
s | ) |
|
|
inlinestatic |
Returns a 128 bit hash of a string using the city hash function. The hash is strong but not cryptographically secure.
- Parameters
-
s | std::string instance to hash. |
Definition at line 846 of file cityhash_tc.hpp.
◆ hash128() [3/8]
static uint128_t turi::hash128 |
( |
uint128_t |
v | ) |
|
|
inlinestatic |
Returns a 128 bit hash of a uint128_t hash value. The hash is unique, has good bit-wise properties, and is very fast.
- Parameters
-
v | 128 bit integer value to hash. |
Definition at line 856 of file cityhash_tc.hpp.
◆ hash128() [4/8]
template<typename T >
static uint128_t turi::hash128 |
( |
const T & |
v | ) |
|
|
inlinestatic |
Returns a 128 bit hash of any integer type up to 64 bits. The hash is unique, has decent bit-wise properties, and is very fast.
- Parameters
-
Definition at line 871 of file cityhash_tc.hpp.
◆ hash128() [5/8]
static uint128_t turi::hash128 |
( |
uint64_t |
v | ) |
|
|
inlinestatic |
Returns a 128 bit hash of a uint128_t hash value. The hash is unique, has good bit-wise properties, and is very fast.
- Parameters
-
v | 64 bit integer value to hash. |
Definition at line 887 of file cityhash_tc.hpp.
◆ hash128() [6/8]
Returns a 128 bit hash of a flexible_type value. The hash is unique, has good bit-wise properties, and is very fast.
- Parameters
-
◆ hash128() [7/8]
uint128_t turi::hash128 |
( |
const std::vector< flexible_type > & |
v | ) |
|
Returns a 128 bit hash of a vector of flexible_type values. The hash is unique, has good bit-wise properties, and is very fast.
- Parameters
-
◆ hash128() [8/8]
static uint128_t turi::hash128 |
( |
const std::vector< std::string > & |
v | ) |
|
|
inlinestatic |
Returns a 128 bit hash of a vector of strings using the city hash function. The hash is strong but not cryptographically secure.
- Parameters
-
v | vector of std::strings to hash. |
Definition at line 1046 of file cityhash_tc.hpp.
◆ hash128_combine()
static uint128_t turi::hash128_combine |
( |
uint128_t |
h1, |
|
|
uint128_t |
h2 |
|
) |
| |
|
inlinestatic |
Updates a hash that is used to track a sequential stream of objects.
- Parameters
-
h | A previous hash value. |
v | A new value to hash. |
- Returns
- The updated hash.
Definition at line 1015 of file cityhash_tc.hpp.
◆ hash128_update()
template<typename T >
static uint128_t turi::hash128_update |
( |
uint128_t |
h, |
|
|
const T & |
v |
|
) |
| |
|
inlinestatic |
Updates a hash that is used to track a sequential stream of objects.
- Parameters
-
h | A previous hash value. |
v | A new value to hash. |
- Returns
- The updated hash.
Definition at line 1036 of file cityhash_tc.hpp.
◆ hash64() [1/9]
static uint64_t turi::hash64 |
( |
const char * |
s, |
|
|
size_t |
len |
|
) |
| |
|
inlinestatic |
Returns a 64 bit hash of a string using the city hash function. The hash is strong but not cryptographically secure.
- Parameters
-
s | char* pointer to data. |
len | Length of data to hash, in bytes. |
Definition at line 917 of file cityhash_tc.hpp.
◆ hash64() [2/9]
static uint64_t turi::hash64 |
( |
const std::string & |
s | ) |
|
|
inlinestatic |
Returns a 64 bit hash of a string using the city hash function. The hash is strong but not cryptographically secure.
- Parameters
-
s | std::string instance to hash. |
Definition at line 927 of file cityhash_tc.hpp.
◆ hash64() [3/9]
static uint64_t turi::hash64 |
( |
uint64_t |
v1, |
|
|
uint64_t |
v2 |
|
) |
| |
|
inlinestatic |
Returns a 64 bit hash of two 64 bit integers. The hash is unique, has good bit-wise properties, and is fairly fast. The hash function is subject to change.
- Parameters
-
v1 | First integer value to hash. |
v2 | Second integer value to hash. |
Definition at line 939 of file cityhash_tc.hpp.
◆ hash64() [4/9]
static uint64_t turi::hash64 |
( |
uint64_t |
v1, |
|
|
uint64_t |
v2, |
|
|
uint64_t |
v3 |
|
) |
| |
|
inlinestatic |
Returns a 64 bit hash of two 64 bit integers. The hash is unique, has good bit-wise properties, and is fairly fast. The hash function is subject to change.
- Parameters
-
v1 | First integer value to hash. |
v2 | Second integer value to hash. |
v3 | Third integer value to hash. |
Definition at line 956 of file cityhash_tc.hpp.
◆ hash64() [5/9]
static uint64_t turi::hash64 |
( |
uint128_t |
v | ) |
|
|
inlinestatic |
Returns a 64 bit hash of a 128 bit integer. The hash is unique, has good bit-wise properties, and is fairly fast. The hash function is subject to change.
- Parameters
-
Definition at line 967 of file cityhash_tc.hpp.
◆ hash64() [6/9]
template<typename T >
static uint64_t turi::hash64 |
( |
const T & |
v | ) |
|
|
inlinestatic |
Returns a 64 bit hash of any integer up to 64 bits. The hash is unique, has good bit-wise properties, and is fairly fast. The hash function is subject to change.
- Parameters
-
Definition at line 986 of file cityhash_tc.hpp.
◆ hash64() [7/9]
Returns a 64 bit hash of a flexible_type value. The hash is unique, has good bit-wise properties, and is very fast.
- Parameters
-
◆ hash64() [8/9]
Returns a 64 bit hash of a vector of flexible_type values. The hash is unique, has good bit-wise properties, and is very fast.
- Parameters
-
◆ hash64() [9/9]
static uint64_t turi::hash64 |
( |
const std::vector< std::string > & |
v | ) |
|
|
inlinestatic |
Returns a 128 bit hash of a vector of strings using the city hash function. The hash is strong but not cryptographically secure.
- Parameters
-
v | vector of std::strings to hash. |
Definition at line 1104 of file cityhash_tc.hpp.
◆ hash64_combine()
static uint64_t turi::hash64_combine |
( |
uint64_t |
h1, |
|
|
uint64_t |
h2 |
|
) |
| |
|
inlinestatic |
Combines two 64 bit hashes in a simple, order dependent way. Produces a new 64 bit hash.
- Parameters
-
h1 | First hash value |
h2 | Second hash value |
Definition at line 1062 of file cityhash_tc.hpp.
◆ hash64_proportion_cutoff()
uint64_t turi::hash64_proportion_cutoff |
( |
double |
proportion | ) |
|
When hash64 is used as a random number function, it is nice to be able to do the following to get a proportion:
uint64_t threshold = hash64_proportion_cutoff(proportion); // ... if(hash64(...) < threshold) { // do something that happens proportion
of the time. }
Unfortunately, this computation of the proportion is prone to numerical issues due to the 48 bits of precision of the double, which this function gets around.
◆ hash64_update()
template<typename T >
static uint64_t turi::hash64_update |
( |
uint64_t |
h1, |
|
|
const T & |
t |
|
) |
| |
|
inlinestatic |
Updates an existing 64 bit hash in a simple, order dependent way.
- Parameters
-
h | First hash value |
t | New object to hash |
Definition at line 1094 of file cityhash_tc.hpp.
◆ index_hash()
static uint64_t turi::index_hash |
( |
uint64_t |
idx | ) |
|
|
inlinestatic |
◆ reverse_index_hash()
static uint64_t turi::reverse_index_hash |
( |
uint64_t |
idx | ) |
|
|
inlinestatic |
◆ simple_random_mapping()
static uint32_t turi::simple_random_mapping |
( |
size_t |
index, |
|
|
size_t |
seed |
|
) |
| |
|
inlinestatic |
Returns a 32bit value based on index and seed that has reasonable pseudorandom properties; I.e. for a given seed, each index maps to effectively random values of size_t.
- Parameters
-
index | Index from which the pseudorandom map value is mapped. |
seed | Random seed governing the mapping. |
Definition at line 1121 of file cityhash_tc.hpp.