Re: Hash map to categorize users.
On 2007-09-13 14:43, LR wrote:
DaveJ wrote:
Thanks guys,
Thats food for thought.
I wanted to avoid just having a map<string, string> implementation as
there would be several users per group, but I guess a pointer to a
vector of groups would be a nice way around that.
Sorry, but why?
Did I misread your original request?
You have many users, each user is a member of a group, you want to be
able to look up a particular user to see what groups they are a member of.
std::map<std::string,std::string> will work just fine for that. Is
there some other requirement or concern you have that I'm missing or
didn't understand?
Memory savings mostly I would suspect, if you have many groups with long
names you can save quite a few bytes by only storing them once.
As for numbers I would expect to have maybe 1000 in each of the three
groups, so I guess I would see benifits of a hash map. Thanks
Probably. Well, maybe. But 1000 doesn't really sound like a very big
number to me. In a Red Black tree (I think that many std::maps are
implemented with RBTs) I think that's going to be at most 10 levels. It
might not save you that much.
I guess another question is, how often are you going to have to read
that file? If the answer is 5000 times a day, then look into speed
problems (but not yet). If the answer is once a month, then maybe not
to worry.
I don't think that the file will be read very often, but lookups might
be performed very often. Never the less, unless this is a very time-
critical app like a like a busy webserver, or very many lookups are
performed in some loop, or some kind of realtime app I don't think there
will be any noticeable difference between std::map and a hashmap on
modern PCs.
--
Erik Wikstr?m