|
-
April 17th, 2010, 07:57 PM
#9
Re: check if a variable is inside a set of values
 Originally Posted by Speedo
IIRC std::set is usually implemented as a binary search tree, so would using a vector offer any real advantage? Especially considering how much uglier it is to write "std::binary_search(myVec.begin(), myVec.end(), value)" everywhere as compared to "mySet.count(value)".
I'm just echoing Effective STL here. Since a vector stores all the values in one place, looking something up in it with binary_search is going to be much more cache-efficient than in a std::set, unless your particular STL implementation takes steps to ensure that nodes in a single container are usually close together in memory.
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
|