BPHash
General object hashing library for C++
|
Namespaces | |
detail | |
Classes | |
class | Hasher |
Class that is used to hash objects. More... | |
struct | is_hashable |
Trait class that determines if a type is hashable or not. More... | |
struct | is_hashable< T * > |
struct | is_hashable< T > |
struct | is_hashable< T, Targs... > |
struct | PointerWrapper |
Wrapper for pointers and arrays. More... | |
struct | StdHash |
A class that can be used in place of std::hash in containers. More... | |
Typedefs | |
typedef std::vector< uint8_t > | HashValue |
Stores the value of a hash. More... | |
Enumerations | |
enum | HashType { HashType::Hash32, HashType::Hash64, HashType::Hash128, HashType::Hash32_x32, HashType::Hash64_x32, HashType::Hash128_x32, HashType::Hash32_x64, HashType::Hash64_x64, HashType::Hash128_x64 } |
Type of hash to use. More... | |
Functions | |
std::string | hash_to_string (const HashValue &hash) |
Return a string representation of a hash. More... | |
HashValue | truncate_hash (const HashValue &hash, size_t nbytes) |
Truncate the hash to a given number of bytes. More... | |
template<typename T > | |
T | convert_hash (const HashValue &hash) |
Convert the hash to a given integral type. More... | |
template<typename T > | |
PointerWrapper< T > | hash_pointer (const T *ptr, size_t len=1) |
Wrap a raw pointer so that it can be hashed. More... | |
template<typename... Targs> | |
HashValue | make_hash (HashType type, const Targs &...objs) |
Convenience function for hashing objects in a single function call. More... | |
template<typename InputIterator > | |
HashValue | make_hash_range (HashType type, InputIterator first, InputIterator last) |
Convenience function hashing selected elements of a container. More... | |
template<typename T , size_t N> | |
std::enable_if< is_hashable< T >::value, void >::type | hash_object (const std::array< T, N > &a, Hasher &h) |
Hashing of std::array. More... | |
template<typename T > | |
std::enable_if< is_hashable< T >::value, void >::type | hash_object (const std::complex< T > &a, Hasher &h) |
Hashing of std::complex. More... | |
template<typename T , typename Alloc > | |
std::enable_if< is_hashable< T >::value, void >::type | hash_object (const std::forward_list< T, Alloc > &a, Hasher &h) |
Hashing of std::forward_list. More... | |
template<typename T , typename Alloc > | |
std::enable_if< is_hashable< T >::value, void >::type | hash_object (const std::list< T, Alloc > &a, Hasher &h) |
Hashing of std::list. More... | |
template<typename Key , typename T , typename Compare , typename Alloc > | |
std::enable_if< is_hashable< Key, T >::value, void >::type | hash_object (const std::map< Key, T, Compare, Alloc > &m, Hasher &h) |
Hashing of std::map. More... | |
template<typename T , typename Deleter > | |
PointerWrapper< T > | hash_pointer (const std::unique_ptr< T, Deleter > &ptr, size_t len=1) |
Create a wrapper around a unique_ptr. More... | |
template<typename T , typename Deleter > | |
PointerWrapper< T > | hash_pointer (const std::unique_ptr< T[], Deleter > &ptr, size_t len) |
Create a wrapper around a unique_ptr. More... | |
template<typename T > | |
PointerWrapper< T > | hash_pointer (const std::shared_ptr< T > &ptr, size_t len=1) |
Create a wrapper around a shared_ptr. More... | |
template<typename T , typename Deleter > | |
std::enable_if< is_hashable< T >::value, void >::type | hash_object (const std::unique_ptr< T, Deleter > &p, Hasher &h) |
Hashing of std::unique_ptr. More... | |
template<typename T > | |
std::enable_if< is_hashable< T >::value, void >::type | hash_object (const std::shared_ptr< T > &p, Hasher &h) |
Hashing of std::shared_ptr. More... | |
template<typename Key , typename Compare , typename Alloc > | |
std::enable_if< is_hashable< Key >::value, void >::type | hash_object (const std::set< Key, Compare, Alloc > &s, Hasher &h) |
Hashing of std::set. More... | |
template<typename charT , typename Traits , typename Alloc > | |
std::enable_if< is_hashable< charT >::value, void >::type | hash_object (const std::basic_string< charT, Traits, Alloc > &s, Hasher &h) |
Hashing of std::string. More... | |
template<typename... Types> | |
std::enable_if< is_hashable< Types... >::value, void >::type | hash_object (const std::tuple< Types... > &tup, Hasher &h) |
template<typename Key , typename T , typename HashT , typename Pred , typename Alloc > | |
std::enable_if< is_hashable< Key, T >::value, void >::type | hash_object (const std::unordered_map< Key, T, HashT, Pred, Alloc > &m, Hasher &h) |
Hashing of std::unordered_map. More... | |
template<typename Key , typename HashT , typename Pred , typename Alloc > | |
std::enable_if< is_hashable< Key >::value, void >::type | hash_object (const std::unordered_set< Key, HashT, Pred, Alloc > &s, Hasher &h) |
Hashing of std::unordered_set. More... | |
template<typename T1 , typename T2 > | |
std::enable_if< is_hashable< T1, T2 >::value, void >::type | hash_object (const std::pair< T1, T2 > &p, Hasher &h) |
Hashing of std::pair. More... | |
template<typename T , typename Alloc > | |
std::enable_if< is_hashable< T >::value, void >::type | hash_object (const std::vector< T, Alloc > &v, Hasher &h) |
Hashing of std::vector. More... | |
template<typename Alloc > | |
void | hash_object (const std::vector< bool, Alloc > &v, Hasher &h) |
Hashing of std::vector<bool> More... | |
typedef std::vector<uint8_t> bphash::HashValue |
|
strong |
Type of hash to use.
Definition at line 25 of file Hasher.hpp.
T bphash::convert_hash | ( | const HashValue & | hash | ) |
Convert the hash to a given integral type.
If the type is larger than the size of the stored hash, it is padded with zeros. Otherwise, the hash it is truncated.
The | type to convert to. Must be an integral type. |
[in] | hash | The hash to convert |
Definition at line 50 of file Hash.hpp.
std::enable_if<is_hashable<T>::value, void>::type bphash::hash_object | ( | const std::complex< T > & | a, |
Hasher & | h | ||
) |
Hashing of std::complex.
Definition at line 20 of file complex.hpp.
std::enable_if<is_hashable<T>::value, void>::type bphash::hash_object | ( | const std::forward_list< T, Alloc > & | a, |
Hasher & | h | ||
) |
Hashing of std::forward_list.
Definition at line 20 of file forward_list.hpp.
std::enable_if<is_hashable<Key>::value, void>::type bphash::hash_object | ( | const std::set< Key, Compare, Alloc > & | s, |
Hasher & | h | ||
) |
std::enable_if<is_hashable<charT>::value, void>::type bphash::hash_object | ( | const std::basic_string< charT, Traits, Alloc > & | s, |
Hasher & | h | ||
) |
Hashing of std::string.
Definition at line 20 of file string.hpp.
std::enable_if<is_hashable<T>::value, void>::type bphash::hash_object | ( | const std::list< T, Alloc > & | a, |
Hasher & | h | ||
) |
std::enable_if<is_hashable<Key>::value, void>::type bphash::hash_object | ( | const std::unordered_set< Key, HashT, Pred, Alloc > & | s, |
Hasher & | h | ||
) |
Hashing of std::unordered_set.
Definition at line 20 of file unordered_set.hpp.
std::enable_if<is_hashable<T1, T2>::value, void>::type bphash::hash_object | ( | const std::pair< T1, T2 > & | p, |
Hasher & | h | ||
) |
Hashing of std::pair.
Definition at line 20 of file utility.hpp.
std::enable_if<is_hashable<T>::value, void>::type bphash::hash_object | ( | const std::array< T, N > & | a, |
Hasher & | h | ||
) |
std::enable_if<is_hashable<Key, T>::value, void>::type bphash::hash_object | ( | const std::map< Key, T, Compare, Alloc > & | m, |
Hasher & | h | ||
) |
std::enable_if<is_hashable<T>::value, void>::type bphash::hash_object | ( | const std::vector< T, Alloc > & | v, |
Hasher & | h | ||
) |
Hashing of std::vector.
Definition at line 21 of file vector.hpp.
std::enable_if<is_hashable<Key, T>::value, void>::type bphash::hash_object | ( | const std::unordered_map< Key, T, HashT, Pred, Alloc > & | m, |
Hasher & | h | ||
) |
Hashing of std::unordered_map.
Definition at line 21 of file unordered_map.hpp.
void bphash::hash_object | ( | const std::vector< bool, Alloc > & | v, |
Hasher & | h | ||
) |
Hashing of std::vector<bool>
Definition at line 29 of file vector.hpp.
std::enable_if<is_hashable<Types...>::value, void>::type bphash::hash_object | ( | const std::tuple< Types... > & | tup, |
Hasher & | h | ||
) |
std::enable_if<is_hashable<T>::value, void>::type bphash::hash_object | ( | const std::unique_ptr< T, Deleter > & | p, |
Hasher & | h | ||
) |
Hashing of std::unique_ptr.
It is assumed that the pointer points to a single element. If not, you must wrap the pointer with hash_pointer.
Definition at line 75 of file memory.hpp.
std::enable_if<is_hashable<T>::value, void>::type bphash::hash_object | ( | const std::shared_ptr< T > & | p, |
Hasher & | h | ||
) |
Hashing of std::shared_ptr.
It is assumed that the pointer points to a single element. If not, you must wrap the pointer with hash_pointer.
Definition at line 88 of file memory.hpp.
PointerWrapper<T> bphash::hash_pointer | ( | const std::unique_ptr< T, Deleter > & | ptr, |
size_t | len = 1 |
||
) |
Create a wrapper around a unique_ptr.
[in] | ptr | The shared pointer to wrap |
[in] | len | The number of elements that ptr points to |
Definition at line 25 of file memory.hpp.
PointerWrapper<T> bphash::hash_pointer | ( | const std::unique_ptr< T[], Deleter > & | ptr, |
size_t | len | ||
) |
Create a wrapper around a unique_ptr.
[in] | ptr | The shared pointer to wrap |
[in] | len | The number of elements that ptr points to |
Definition at line 39 of file memory.hpp.
PointerWrapper<T> bphash::hash_pointer | ( | const std::shared_ptr< T > & | ptr, |
size_t | len = 1 |
||
) |
Create a wrapper around a shared_ptr.
[in] | ptr | The shared pointer to wrap |
[in] | len | The number of elements that ptr points to |
Definition at line 51 of file memory.hpp.
PointerWrapper<T> bphash::hash_pointer | ( | const T * | ptr, |
size_t | len = 1 |
||
) |
Wrap a raw pointer so that it can be hashed.
Small helper function to help create PointerWrapper objects more cleanly.
[in] | ptr | Pointer to be hashed |
[in] | len | Number of elements of T that ptr points to |
Definition at line 67 of file Hasher.hpp.
std::string bphash::hash_to_string | ( | const HashValue & | hash | ) |
Return a string representation of a hash.
The string representation is the usual hex representation, with lower case letters. The length of the string will be 2*number_of_bits/8 characters.
[in] | hash | The hash to convert |
Definition at line 17 of file Hash.cpp.
Convenience function for hashing objects in a single function call.
This can be used to easily obtain the hash of several objects at once without needing to manually create a Hasher object, etc.
[in] | type | The type of hash to use |
[in] | objs | Objects to hash |
Definition at line 254 of file Hasher.hpp.
HashValue bphash::make_hash_range | ( | HashType | type, |
InputIterator | first, | ||
InputIterator | last | ||
) |
Convenience function hashing selected elements of a container.
This can be used to easily obtain the hash of a range of objects in a container (given via two iterators).
Objects in the range [first, last) are hashed (generally the same convention as the STL)
[in] | type | The type of hash to use |
[in] | first | An iterator of the first object to hash |
[in] | last | An iterator of the element following the last element to hash |
Definition at line 276 of file Hasher.hpp.
Truncate the hash to a given number of bytes.
If the desired size is larger than the size of the size of the given hash, the new hash is padded with zeroes.
[in] | hash | The hash to truncate |
[in] | nbytes | Desired size of the new hash (in bytes) |
Definition at line 32 of file Hash.cpp.