Often, it is more efficient to use a sorted std::vector instead of a std::set. Does anyone know a library class sorted_vector, which b
If you decide to roll your own, you might also want to check out boost:ublas. Specifically:
#include
and look at coordinate_vector, which implements a vector of values and indexes. This data structure supports O(1) insertion (violating the sort), but then sorts on-demand Omega(n log n). Of course, once it's sorted, lookups are O(logn). If part of the array is sorted, the algorithm recognizes this and sorts only the newly added elements, then does an inplace merge. If you care about efficiency, this is probably the best you can do.