-
May 16th, 2013, 01:35 PM
#1
Searching a vector of objects for pairs
Hello all,
Say I have a vector of objects and I want to return an object based on a pair of strings. The strings can be in either order Ie; A B==B A.
In general, what do you think is the best way to do this?
Thanks,
T.
-
May 16th, 2013, 02:32 PM
#2
Re: Searching a vector of objects for pairs
 Originally Posted by azeotrope
In general, what do you think is the best way to do this?
There can be varying opinion on what is the "best way".
http://www.cplusplus.com/reference/algorithm/find_if/
Regards,
Paul McKenzie
-
May 16th, 2013, 02:39 PM
#3
Re: Searching a vector of objects for pairs
I think you have to provide more details to get a serious answer.
Edit: Sorry Paul, was typing a response but changed my mind before posting so your response was not accounted for.
Last edited by S_M_A; May 16th, 2013 at 02:46 PM.
-
May 16th, 2013, 02:42 PM
#4
Re: Searching a vector of objects for pairs
 Originally Posted by S_M_A
I think you have to provide more details to get a serious answer.
I agree, the question doesn't make much sense. Sounds to me like you may want a map.
-
May 17th, 2013, 05:58 PM
#5
Re: Searching a vector of objects for pairs
You may want to consider a sorted vector or a map as stated above.
-
May 17th, 2013, 06:37 PM
#6
Re: Searching a vector of objects for pairs
 Originally Posted by azeotrope
Say I have a vector of objects and I want to return an object based on a pair of strings. The strings can be in either order Ie; A B==B A.
Well, if you search the vector from begin to end you'll have O(N) complexity.
But if you introduce an extra unordered_map you can get O(1) accesses into the vector.
Tags for this Thread
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
|