I have sorted data coming from a database to initialize an STL map. Only 5% of data will be changed later on inside the map.
As I understand, there will be an overhead of rotations incurred for each insertions. Is it possible to bypass the overhead for sorted data? e.g. is there an option to skip rotation, and another STL algoritm to do create a balanced tree with sorted data?
PS : I am aware there will be only 2 max rotations, but was wondering if I can improve performance further.
By default, a Map in C++ is sorted in increasing order based on its key.
STL Map Internal Implementation: It's implemented as a self-balancing red-black tree. Probably the two most common self balancing trees are red-black tree and AVL trees.
Maps are associative containers that store elements in a mapped fashion. Each element has a key value and a mapped value. No two mapped values can have the same key values.
I assume you're interesting only in efficient loading of the initial sorted data?
The standard map :: map (InputIterator first, InputIterator last) constructor seems to do the right thing.
"For the iterator constructor, linear in the distance between the iterators (copy constructions) if the elements are already sorted according to comp. For unsorted sequences, linearithmic (N*logN) in that distance (sorting,copy constructions)."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With