Hi. I have a class like this:
class Foo
{
long long Id;
string x;
string y;
// other member variables and functions
};
I would like to store this in a hash_set (or hash_map), but use the Id member variable as the key for inserting and searching. I'm not sure how I can do this. I thought of the following ways, but none of them are really good:
1) I can write a custom hash function that will hash the object using the Id, but then I can't use the find() method on hash_set to lookup the item by Id (long long) since it will require a Foo object to be passed-in.
2) I can duplicate the Id and create a hash_map instead of a hash_set but I have 100 million instances of these objects so I'd rather not duplicate the Id field.
3) I can move the Id field outside of Foo and then do hash_map, but it would be kind of messy since the Id is used internally by the class and it would be better to keep it with Foo.
Any ideas? What I'm looking for is a way to store Foo objects but be able to search for them in the hash_set using a long long (by Id).
Thanks!