Hasher< T > Struct Template Reference

Hasher<T> is a class object which pretends to be a function which returns a semi-unique value for objects you pass it. That is, it returns you an integer value which can be used as a hash code in various algoriths. To use a Hasher, you declare a Hasher object, then execute it like a function in order to get a hash value. For example: More...

#include <hashers.h>

Inheritance diagram for Hasher< T >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

unsigned int operator() (T const &t)

Detailed Description

template<class T>
struct cxxtls::Hasher< T >

Hasher<T> is a class object which pretends to be a function which returns a semi-unique value for objects you pass it. That is, it returns you an integer value which can be used as a hash code in various algoriths. To use a Hasher, you declare a Hasher object, then execute it like a function in order to get a hash value. For example:

     Hasher<std::string> h;
     int hashcode = h("stuff");

Hash values are unsigned int.

This basic implementation is meant for integral and pointer types. Other built in types are supported, feel free to follow the paradigm for your own class objects. If you decide to create your own hasher, be careful not to fall into the trap of trying to make the hash value dependent on every single byte in your class object -- as is shown in the hasher's for string, double, and float. The compiler will leave empty spaces in your class objects to align datatypes for maximum speed. These empty spaces are not consistently valued -- and using in your hasher algorithm will result in inconsistent results.

If your class object consists of pieces which can individually be hashed, you might consider a hash algorith that combines the hashes of all the separate pieces. Say by orring them together after shifting, or something.

Please ignore this line of the comment. symbols/B}@.

Definition at line 43 of file hashers.h.


Member Function Documentation

unsigned int operator() ( T const &  t  ) 

Definition at line 77 of file hashers.h.


The documentation for this struct was generated from the following file:
Generated on Wed Feb 29 22:55:54 2012 for CXXUtilities by  doxygen 1.6.3