-
March 5th, 2010, 10:34 PM
#1
searching a map
Cna someone please help...I am trying to search a map by a give string "userName" but the map has an int key value
Status::Code ChatRoomManager::NewChatRoom(ChatRoomInfo* chatRoom_info)
map<int, ClientInfo*> clients;
-
March 5th, 2010, 11:10 PM
#2
Re: searching a map
What is the connection between the map and username ?
-
March 5th, 2010, 11:14 PM
#3
Re: searching a map
Sorry username is a bit misguiding. I am trying to search for the chatrooms contained in the map by their name " chat_name"
-
March 5th, 2010, 11:21 PM
#4
Re: searching a map
You have no choice but to just iterate thru the map and check
the chat_name.
Why do you have an int as the key, if you want to search using
chatname ?
-
March 5th, 2010, 11:32 PM
#5
Re: searching a map
I have to write 2 separate functions, one to search by room ID and one to search by name. What would be the effect of using 2 maps one with string key and the other with an int key?
-
March 6th, 2010, 01:18 AM
#6
Re: searching a map
Originally Posted by jc35
I have to write 2 separate functions, one to search by room ID and one to search by name. What would be the effect of using 2 maps one with string key and the other with an int key?
That can work, but you have to be careful to keep them in sync. Alternatively, you may be able to use Boost.Bimap.
-
March 6th, 2010, 08:24 AM
#7
Re: searching a map
Another option would be to define a map<string,int> which maps from the name to the integer you need to look up into the other map. The downside is two lookups are required when starting from a name, but in some cases it might be easier to keep things managable than throwing a pointer into two different maps.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|