 Timestamp:
 Jul 22, 2008, 7:32:53 PM (14 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/yat/utility/stl_utility.h
r1341 r1385 39 39 #include <cmath> 40 40 #include <functional> 41 #include <map> 41 42 #include <ostream> 42 43 #include <string> 43 44 #include <utility> 45 #include <vector> 46 47 // debug 48 #include <iostream> 44 49 45 50 namespace std { … … 133 138 { return std::exp(x); } 134 139 }; 140 141 /** 142 Creating a map from a range [first, last) such that m[key] 143 returns a vector with indices of which element in [first, last) 144 that is equal to \a key, or more technically: m[element].size() 145 returns number of elements equal to \a element, and 146 m[*element][i] = distance(first, element) for every \a element in 147 [first, last) and \a i smaller than m[element].size(). 148 149 Requirement: InputIterator's value type is assignable to Key 150 151 \since New in yat 0.5 152 */ 153 template<typename InputIterator, typename Key> 154 void inverse(InputIterator first, InputIterator last, 155 std::map<Key, std::vector<size_t> >& m) 156 { 157 m.clear(); 158 for (size_t i=0; first!=last; ++i, ++first) 159 m[*first].push_back(i); 160 } 161 162 /** 163 In the created multimap each element e will fulfill: \f$ *(first 164 + e>second) == e>first \f$ 165 166 Requirement: InputIterator's value type is assignable to Key 167 168 \since New in yat 0.5 169 */ 170 template<typename Key, typename InputIterator> 171 void inverse(InputIterator first, InputIterator last, 172 std::multimap<Key, size_t>& m) 173 { 174 m.clear(); 175 for (size_t i=0; first!=last; ++i, ++first) 176 m.insert(std::make_pair(*first, i)); 177 } 178 135 179 136 180 /**
Note: See TracChangeset
for help on using the changeset viewer.