STL compliant sorted vector class (std::map replacement) from CodeProject.
authorDariusz Murakowski <murakdar@mit.edu>
Wed, 20 Aug 2014 20:26:56 +0000 (16:26 -0400)
committerDariusz Murakowski <murakdar@mit.edu>
Wed, 20 Aug 2014 20:31:26 +0000 (16:31 -0400)
commit6d15f6a14df7cc31db311e4c55c9cda2f8037701
tree375eec6837d6e88ba4649f5c96641404b55eb96f
parent07536fb80d5ef156f6d4902f33c5bf0aa01b1208
STL compliant sorted vector class (std::map replacement) from CodeProject.

Source:
http://www.codeproject.com/Articles/3217/An-STL-compliant-sorted-vector?display=Print

Introduction:

sorted_vector adapts a std::vector to the interface required by
std::set/std::multiset, thereby providing set/multiset and vector
functionality (random access) in one container.

Tests show that sorted_vector's element retrieval (find) speed
outperforms that of std::set/std::multiset by a factor of 2 (on most
machines). On the downward side is the poor performance of
sorted_vector's insert member function, because it inserts an element
somewhere in the middle of the sorted vector in order to preserve the
sort order. By using sorted_vector's low level interface one can solve
this performance bottleneck by inserting a bunch of objects using a
series of push_back's followed by a call to the member function sort,
which restores the sort order.

sorted_vector should be preferred over std::set/std::multiset if many
small elements must be stored. Most STL implementations use a variant of
a balanced tree to implement set and multiset, which imposes a per
element storage overhead of 3 pointers. The most important reason to use
a std::set/std::multiset instead of sorted_vector is the need to keep
iterators into a set/multiset while inserting more elements into the
set. These iterators remain valid in the case of a set/multiset, but are
invalidated in the case of a sorted_vector container.
main.cpp [new file with mode: 0644]
sorted_vector.dsp [new file with mode: 0644]
sorted_vector.h [new file with mode: 0644]
sorted_vector_doc.html [new file with mode: 0644]
sorted_vector_src.zip [new file with mode: 0644]