Jump to content
  • Advertisement
Sign in to follow this  
lucky6969b

hash_map will this work?

This topic is 2514 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


stdext::hash_map<Coord *, bool> m_SparseMap;

void CooperativeTable::ReservePos(Coord* pos)
{
m_SparseMap[pos] = false;
}

Will the compiler automatically sort out the correct index and buckets i need?
Coord contains x,y and time i think
Thanks
Jack

Share this post


Link to post
Share on other sites
Advertisement
Will the compiler automatically sort out the correct index and buckets i need?[/quote]

What would "correct" mean in this case? What do you "need"?

Share this post


Link to post
Share on other sites
I want to hash a key of combination of a coordinate plus its time...
By the time of response, i have separate time and location into 2 tiers.
Thanks for helping
Jack

Share this post


Link to post
Share on other sites
Probably not. It most likely will use a hash based on the value of the pointer by default, not what the pointer points to.

Share this post


Link to post
Share on other sites
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

If it creates a hash based on the pointer value, and not what it points to, it doesn't matter if it points to values or if it points to pointers. It won't care either way.

[/font]

Share this post


Link to post
Share on other sites
You would need to supply a hashing function which could deal with the object type and generate a hash accordingly.

For example our hash_map at work allows keys of char * by having a hashing function which knows that a char * is a 'string' and that it should has what it points to rather than the value the pointer holds.

Share this post


Link to post
Share on other sites
Assuming you're referring to the MSVC stdext::hash_map class, the best course would probably to use a struct/class key type instead of a pointer. Then provide a hash_value() function that takes that struct type and returns a hash and overload operator< for your type.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!