Here is how you can do it.
class MyClass_Hasher { const size_t bucket_size = 10; // mean bucket size that the container should try not to exceed const size_t min_buckets = (1 << 10); // minimum number of buckets, power of 2, >0 MyClass_Hasher() { // should be default-constructible } size_t operator()(const MyClass &key) { size_t hash_value; // do fancy stuff here with hash_value // to create the hash value. There no specific // requirement on the value. return hash_value; } bool operator()(const MyClass &left, const MyClass &right) { // this should implement a total ordering on MyClass, that is // it should return true if "left" precedes "right" in the ordering } };
Then you can just use
stdext::hash_map my_map<MyClass, MyValue, MyClass_Hasher>
ASk
source share