Definition in file InsertSortedVector.h.
#include <vector>
#include <map>
Go to the source code of this file.
Functions | |
| template<typename FIRST, typename SECOND> | |
| void | tf_InsertSortedVector (std::vector< std::pair< FIRST, SECOND > > &vect_pair_data, std::map< FIRST, SECOND > &mp) |
| This function takes vector of pairs which are sorted by the first element, and inserts them into a map, so that the map is balanced on the first pass, and does not require automatic rebalancing. This is most useful, for implementations of map which do not have rebalancing, or have inefficient rebalancing. In a naively programmed map this causes worst case performance for the tree. For a binary tree, which does not rebalance, inserting a sorted list, causes the binary tree to have a depth of N, where N is the number of items in the sorted vector. The tf at the beginning of the function name denotes, "template function". | |
| void tf_InsertSortedVector | ( | std::vector< std::pair< FIRST, SECOND > > & | vect_pair_data, | |
| std::map< FIRST, SECOND > & | mp | |||
| ) |
This function takes vector of pairs which are sorted by the first element, and inserts them into a map, so that the map is balanced on the first pass, and does not require automatic rebalancing. This is most useful, for implementations of map which do not have rebalancing, or have inefficient rebalancing.
In a naively programmed map this causes worst case performance for the tree. For a binary tree, which does not rebalance, inserting a sorted list, causes the binary tree to have a depth of N, where N is the number of items in the sorted vector.
The tf at the beginning of the function name denotes, "template function".
tf_InsertSortedVector
Assumes: for i < j, vect_pair_data[i].first < fct[j].first
Changes: contents of mp
Returns: nothing Description: This function takes vector of pairs which are sorted by the first element, and inserts them into a map, so that the map is balanced on the first pass, and does not require automatic rebalancing. This is most useful, for implementations of map which do not have rebalancing, or have inefficient rebalancing. The tf at the beginning of the function name denotes, "template function".
Definition at line 40 of file InsertSortedVector.h.
00041 { 00042 std::vector<bool> is_used( vect_pair_data.size(), false); 00043 std::vector<bool>::iterator p_is_used; 00044 size_t i, j; 00045 00046 if (!mp.empty()) mp.clear(); 00047 00048 for (i= vect_pair_data.size()/2; i!=0; i/=2) { 00049 for (j=0; j<vect_pair_data.size(); j+=i) { 00050 if (!is_used[j]) { 00051 is_used[j] = true; 00052 //mp[vect_pair_data[j].first] = vect_pair_data[j].second(); 00053 mp.insert( mp.begin(), vect_pair_data[j]); 00054 } 00055 } 00056 } 00057 }
1.5.1