Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
JenkinsHasher Class Reference

Detailed Description

Perform compositional hashing of data (for hash table for example) combining hash of simple data using the XOR operation.

Although the function hash_jenkins() does the same, it is not recommended to use it as is on custom classes. Depending on the type of attributes, padding bytes may be inserted and not initialized. When the hash_jenkins is called on such an object, this padding bytes will be involved in the hash and therefore, two equal objects (from the logicial point of view of the application) may produce a different hash values.

Instead, the best approach is to propose your own hash function and to use this object as an accumulator of the field hash as below:

class MyClass {
bool f1;
int f2;
string f3;
};
namespace elm {
template class<> class HashKey<MyClass> {
public:
static bool equals(const MyClass& o1, const MyClass& o2) { return o1 == o2; }
static t::hash hash(const MyClass& o) { return Hasher() << f1 << f2 << f3; }
};
} // elm

The documentation for this class was generated from the following file:
class
elm::equals
bool equals(const C1 &c1, const C2 &c2)
Definition: util.h:107
elm
Definition: adapter.h:26
elm::hash
t::hash hash(const T &x)
Definition: hash.h:155