Turi Create  4.0

A generic set of hashing functions built around Google's cityhash. More...

Functions

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)
 

Detailed Description

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.

Function Documentation

◆ 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
schar* pointer to data.
lenLength 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
sstd::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
v128 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
vinteger value to hash.

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
v64 bit integer value to hash.

Definition at line 887 of file cityhash_tc.hpp.

◆ hash128() [6/8]

uint128_t turi::hash128 ( const flexible_type v)

Returns a 128 bit hash of a flexible_type value. The hash is unique, has good bit-wise properties, and is very fast.

Parameters
vflexible_type value to hash.

◆ 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
vvector of flexible_type values to hash.

◆ 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
vvector 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
hA previous hash value.
vA 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
hA previous hash value.
vA 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
schar* pointer to data.
lenLength 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
sstd::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
v1First integer value to hash.
v2Second 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
v1First integer value to hash.
v2Second integer value to hash.
v3Third 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
vinteger value to hash.

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
vinteger value to hash.

Definition at line 986 of file cityhash_tc.hpp.

◆ hash64() [7/9]

uint64_t turi::hash64 ( const flexible_type v)

Returns a 64 bit hash of a flexible_type value. The hash is unique, has good bit-wise properties, and is very fast.

Parameters
vflexible_type value to hash.

◆ hash64() [8/9]

uint64_t turi::hash64 ( const std::vector< flexible_type > &  v)

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
vvector of flexible_type values to hash.

◆ 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
vvector 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
h1First hash value
h2Second 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
hFirst hash value
tNew object to hash

Definition at line 1094 of file cityhash_tc.hpp.

◆ index_hash()

static uint64_t turi::index_hash ( uint64_t  idx)
inlinestatic

Provides a simple, reversable hash for indices. This hash has excellent mixing properties, preserves 0 (i.e. 0 maps to 0), and is reversable by calling reverse_index_hash(...) below.

Taken from the Murmur3 finalizer routine. Reference: http://code.google.com/p/smhasher/wiki/MurmurHash3.

Definition at line 1136 of file cityhash_tc.hpp.

◆ reverse_index_hash()

static uint64_t turi::reverse_index_hash ( uint64_t  idx)
inlinestatic

The reverse of index_hash. Gets the index from the index_hash

Definition at line 1157 of file cityhash_tc.hpp.

◆ 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
indexIndex from which the pseudorandom map value is mapped.
seedRandom seed governing the mapping.

Definition at line 1121 of file cityhash_tc.hpp.