hash_map will this work?

Started by
7 comments, last by SiCrane 12 years, 2 months ago

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
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"?
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
Probably not. It most likely will use a hash based on the value of the pointer by default, not what the pointer points to.
How about converting Coord* into pointers
int *x;
int *y;
int *time;
Thanks
Jack
[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]

How would I design a hash_map that has x,y,time as keys and score as output?
Could you please give an example?
Thanks
Jack
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.
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.

This topic is closed to new replies.

Advertisement