Jump to content
  • Advertisement
Sign in to follow this  
ArnoAtWork

hashmap

This topic is 4910 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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;

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!