Reference Guide: Hashing Functions

Hashers are functions able calculate a unsigned number for any data type provided. They are a requirement of Hash Table data structure and thus must be provided for all classes that depend on latter. API makes it extremely easy by asking you to just specialize default hasher for each type you want to support.

For testing purposes, API already ships with two specializations: one for long data type, the other for char* data type. Let's say, for example, you want it to support double data type as well! In that case you need to provide a specialization such as:

template<> inline int hash(const double& item) { std::size_t hash; memcpy(&hash, &item, sizeof(double)); return hash & 0xfffff000; }

hash

Function implementing a hasher (requirement of HashTable) that by default does nothing, to be extended by developers through template specialization for each data type they want to support

Signature

template <typename T> inline std::size_t hash(const T& item)

hash<long>

Function specializing default hasher for LONG data type, implemented by API already

Signature

template <> inline std::size_t hash(const long& item)

hash<char*>

Function specializing default hasher for CHAR* data type, implemented by API already

Signature

template <> inline std::size_t hash(const char*& item)
Share