|
-
April 17th, 2010, 08:51 PM
#16
Re: check if a variable is inside a set of values
Sounds like it's just syntactic sugar wrapping the vector/algorithm approach. Still, keeping the interface consistent is a nice touch since it would make timing the speed difference between the approaches similar.
I'd imagine that inserting everything via the set interface would be O(n^2 lg n). However, as stated in the link, you can use the "low level interface" (read: underlying vector push_back) to insert everything in O(n lg n) by only doing the sort once at the end rather than on every insertion.
-
April 17th, 2010, 09:12 PM
#17
Re: check if a variable is inside a set of values
 Originally Posted by Lindley
Sounds like it's just syntactic sugar wrapping the vector/algorithm approach.
Well it's kinda like a priorty_queue. All it does is wrap another container, and provide a modified interface for a specific use.
So yeah, syntactic sugar, but that's what we're asking for.
 Originally Posted by Lindley
I'd imagine that inserting everything via the set interface would be O(n^2 lg n). However, as stated in the link, you can use the "low level interface" (read: underlying vector push_back) to insert everything in O(n lg n) by only doing the sort once at the end rather than on every insertion.
You are probably right, I didn't do a full study of that container. but as said previously, the goal of such a container is really to be filled only once, and then never touched again. So being able to optimize that phase is just the cherry on the cake .
PS. If you know what you are doing, you could fill it in o(n) by using insertion with hint. That would require the input being pre-sorted, but not an impossible assumption. But again, who cares?
Last edited by monarch_dodra; April 17th, 2010 at 09:14 PM.
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
|