hashmap

Started by
3 comments, last by ArnoAtWork 19 years, 2 months ago
I'am using std::hash_map for several manager of my system. When the key name used to specify a ressource is too big, the resulting hashed value is identical... Does STL uses the first caracters to hash? How can I modify this, or should I use a fixed name size? Thanks a lot.
Advertisement
Even though it is prefixed by std:: hash_map is not part of c++ standard, so you have to tell us which C++ environment you are using.
Ho, sorry!

I'am using stdext::hash_map of VC7.1.
Quote:Original post by ArnoAtWork
Does STL uses the first caracters to hash?


This is implementation dependent.

Quote:Original post by ArnoAtWork
How can I modify this, or should I use a fixed name size?

....

I'am using stdext::hash_map of VC7.1.


VC++ 7.1 hash_map's interface is not exactly the same as SGI's and the one defined in C++ 0x03 TR1 standard, any ways its quite easy to provide a custom hasher for VC++ 7.1's hash_map you can use mine as an example or use it entirely up to you:

#include <cstddef>#include <locale>#include <string>struct cust_string_comp {   const size_t bucket_size;   const size_t min_buckets;	   cust_string_comp(): bucket_size(4), min_buckets(8) {}   size_t operator()(const std::string& Key) const {	const std::collate< char >& c = std::use_facet< std::collate< char > >(std::locale::classic());	return c.hash(Key.c_str(), Key.c_str() + Key.size());   }	   bool operator()(const std::string& Key1, const std::string& Key2) const {	return Key1 < Key2;   }};#include <hash_map>typedef stdext::hash_map< std::string, std::string, cust_string_comp > foo_bar_map;
Hummm, I see.

How to set bucket_size and min_buckets to be sure not to have same ID for different text. Does a text have to be limited in size?

This topic is closed to new replies.

Advertisement