P
Phil Endecott
Dear All,
I have some code that first populates a std::set, and subsequently does
a mixture of tests-for-presence and deletions. As I understand it,
populating the set will be O(N log N), since each of the N inserts will
be O(log N), and the test and deletes will each be O(log N).
In this case, however, I am populating it with values in ascending order
- it's actually a for loop. I feel that because of this it should be
possible to populate the set in O(N) time. This would be possible if
std::set had an O(1) 'append'-like operation.
Can anyone suggest how I could go about getting this reduced complexity,
if indeed it is possible? I could use a sorted std::vector, which has
O(1) append and could have an O(log N) find using a binary chop (is
there a std::algorithm that will do that for me?), but it doesn't have
an O(log N) delete operation; a sorted std::list does have good delete
performance but lacks O(log N) find. Any ideas?
Cheers,
--Phil.
I have some code that first populates a std::set, and subsequently does
a mixture of tests-for-presence and deletions. As I understand it,
populating the set will be O(N log N), since each of the N inserts will
be O(log N), and the test and deletes will each be O(log N).
In this case, however, I am populating it with values in ascending order
- it's actually a for loop. I feel that because of this it should be
possible to populate the set in O(N) time. This would be possible if
std::set had an O(1) 'append'-like operation.
Can anyone suggest how I could go about getting this reduced complexity,
if indeed it is possible? I could use a sorted std::vector, which has
O(1) append and could have an O(log N) find using a binary chop (is
there a std::algorithm that will do that for me?), but it doesn't have
an O(log N) delete operation; a sorted std::list does have good delete
performance but lacks O(log N) find. Any ideas?
Cheers,
--Phil.