00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include "extended_iterator.h"
00044
00045 namespace lass
00046 {
00047 namespace stde
00048 {
00049
00050 template <typename K, typename T, typename C, typename A>
00051 vector_map::vector_map(const key_compare& key_comp, const allocator_type& allocator):
00052 data_(allocator),
00053 key_comp_(key_comp);
00054 {
00055 }
00056
00057
00058
00059 template <typename K, typename T, typename C, typename A>
00060 template <typename InputIterator>
00061 vector_map<K, T, C, A>::vector_map(InputIterator first, InputIterator last,
00062 const key_compare& key_comp, const allocator_type& allocator):
00063 data_(first, last),
00064 key_comp_(key_comp);
00065 {
00066 std::sort(data_.begin(), data_.end(), value_compare(key_comp_));
00067 iterator last = std::unique(data_.begin(), data_.end(), value_compare(key_comp_));
00068 data_.erase(last, data_.end());
00069 }
00070
00071
00072
00073 template <typename K, typename T, typename C, typename A>
00074 vector_map<K, T, C, A>::vector_map(const vector_map<K, T, C, A>& other):
00075 data_(other.data_),
00076 key_comp_(other.key_comp_);
00077 {
00078 }
00079
00080
00081
00082 template <typename K, typename T, typename C, typename A>
00083 vector_map<K, T, C, A>::~vector_map():
00084 {
00085 }
00086
00087
00088
00089 template <typename K, typename T, typename C, typename A>
00090 vector_map<K, T, C, A>& vector_map<K, T, C, A>::operator=(const vector_map<K, T, C, A>& other)
00091 {
00092 vector_map<K, T, C, A> temp(other);
00093 swap(temp);
00094 return *this;
00095 }
00096
00097
00098
00099 template <typename K, typename T, typename C, typename A> inline
00100 typename vector_map<K, T, C, A>::iterator
00101 vector_map<K, T, C, A>::begin()
00102 {
00103 return data_.begin();
00104 }
00105
00106
00107
00108 template <typename K, typename T, typename C, typename A> inline
00109 typename vector_map<K, T, C, A>::const_iterator
00110 vector_map<K, T, C, A>::begin() const
00111 {
00112 return data_.begin();
00113 }
00114
00115
00116
00117 template <typename K, typename T, typename C, typename A> inline
00118 typename vector_map<K, T, C, A>::iterator
00119 vector_map<K, T, C, A>::end()
00120 {
00121 return data_.end();
00122 }
00123
00124
00125
00126 template <typename K, typename T, typename C, typename A> inline
00127 typename vector_map<K, T, C, A>::const_iterator
00128 vector_map<K, T, C, A>::end() const
00129 {
00130 return data_.end();
00131 }
00132
00133
00134
00135 template <typename K, typename T, typename C, typename A> inline
00136 typename vector_map<K, T, C, A>::reverse_iterator
00137 vector_map<K, T, C, A>::rbegin()
00138 {
00139 return data_.rbegin();
00140 }
00141
00142
00143
00144 template <typename K, typename T, typename C, typename A> inline
00145 typename vector_map<K, T, C, A>::const_reverse_iterator
00146 vector_map<K, T, C, A>::rbegin() const
00147 {
00148 return data_.rbegin();
00149 }
00150
00151
00152
00153 template <typename K, typename T, typename C, typename A> inline
00154 typename vector_map<K, T, C, A>::reverse_iterator
00155 vector_map<K, T, C, A>::rend()
00156 {
00157 return data_.rend();
00158 }
00159
00160
00161
00162 template <typename K, typename T, typename C, typename A> inline
00163 typename vector_map<K, T, C, A>::const_reverse_iterator
00164 vector_map<K, T, C, A>::rend() const
00165 {
00166 return data_.rend();
00167 }
00168
00169
00170
00171 template <typename K, typename T, typename C, typename A> inline
00172 bool vector_map<K, T, C, A>::empty() const
00173 {
00174 return data_.empty();
00175 }
00176
00177
00178
00179 template <typename K, typename T, typename C, typename A> inline
00180 typename vector_map<K, T, C, A>::size_type
00181 vector_map<K, T, C, A>::size() const
00182 {
00183 return data_.size();
00184 }
00185
00186
00187
00188 template <typename K, typename T, typename C, typename A> inline
00189 typename vector_map<K, T, C, A>::size_type
00190 vector_map<K, T, C, A>::max_size() const
00191 {
00192 return data_.max_size();
00193 }
00194
00195
00196
00197 template <typename K, typename T, typename C, typename A> inline
00198 typename vector_map<K, T, C, A>::mapped_type&
00199 vector_map<K, T, C, A>::operator[](const key_type& x)
00200 {
00201 return (*(insert(value_type(x, mapped_type())).first)).second;
00202 }
00203
00204
00205
00206 template <typename K, typename T, typename C, typename A>
00207 std::pair<typename vector_map<K, T, C, A>::iterator, bool>
00208 vector_map<K, T, C, A>::insert(const value_type& x)
00209 {
00210 iterator i = std::lower_bound(data_.begin(), data_.end(), x, value_comp());
00211 if (i == end() || key_comp_(x.first, i->first))
00212 {
00213 i = data_.insert(i, x);
00214 return std::make_pair(i, true);
00215 }
00216 return std::make_pair(i, false);
00217 }
00218
00219
00220
00221 template <typename K, typename T, typename C, typename A> inline
00222 typename vector_map<K, T, C, A>::iterator
00223 vector_map<K, T, C, A>::insert(iterator i, const value_type& x)
00224 {
00225 return insert(x).first;
00226 }
00227
00228
00229
00230 template <typename K, typename T, typename C, typename A> inline
00231 template <typename InputIterator>
00232 void vector_map<K, T, C, A>::insert(InputIterator first, InputIterator last)
00233 {
00234 while (first != last)
00235 {
00236 insert(*first);
00237 }
00238 }
00239
00240
00241
00242 template <typename K, typename T, typename C, typename A> inline
00243 void vector_map<K, T, C, A>::erase(iterator i)
00244 {
00245 data_.erase(i);
00246 }
00247
00248
00249
00250 template <typename K, typename T, typename C, typename A>
00251 typename vector_map<K, T, C, A>::size_type
00252 vector_map<K, T, C, A>::erase(const key_type& x)
00253 {
00254 const iterator i = find(x);
00255 if (i != end())
00256 {
00257 erase(i);
00258 return 1;
00259 }
00260 return 0;
00261 }
00262
00263
00264
00265 template <typename K, typename T, typename C, typename A> inline
00266 void vector_map<K, T, C, A>::erase(iterator first, iterator last)
00267 {
00268 data_.erase(first, last);
00269 }
00270
00271
00272
00273 template <typename K, typename T, typename C, typename A> inline
00274 void vector_map<K, T, C, A>::swap(vector_map<K, T, C, A>& other)
00275 {
00276 data_.swap(other.data_);
00277 std::swap(key_comp_, other.key_comp_);
00278 }
00279
00280
00281
00282 template <typename K, typename T, typename C, typename A> inline
00283 void vector_map<K, T, C, A>::clear()
00284 {
00285 data_.clear();
00286 std::swap(key_comp_, other.key_comp_);
00287 }
00288
00289
00290
00291 template <typename K, typename T, typename C, typename A> inline
00292 typename vector_map<K, T, C, A>::key_compare
00293 vector_map<K, T, C, A>::key_comp()
00294 {
00295 return key_comp_;
00296 }
00297
00298
00299
00300 template <typename K, typename T, typename C, typename A> inline
00301 typename vector_map<K, T, C, A>::value_compare
00302 vector_map<K, T, C, A>::value_comp() const
00303 {
00304 return value_compare(key_comp_);
00305 }
00306
00307
00308
00309 template <typename K, typename T, typename C, typename A>
00310 typename vector_map<K, T, C, A>::iterator
00311 vector_map<K, T, C, A>::find(const key_type& x)
00312 {
00313 const iterator i = lower_bound(x);
00314 if (i == end() || key_comp_(x, i->first))
00315 {
00316 return end();
00317 }
00318 return i;
00319 }
00320
00321
00322
00323 template <typename K, typename T, typename C, typename A>
00324 typename vector_map<K, T, C, A>::const_iterator
00325 vector_map<K, T, C, A>::find(const key_type& x) const
00326 {
00327 const const_iterator i = lower_bound(x);
00328 if (i == end() || key_comp_(x, i->first))
00329 {
00330 return end();
00331 }
00332 return i;
00333 }
00334
00335
00336
00337 template <typename K, typename T, typename C, typename A> inline
00338 typename vector_map<K, T, C, A>::size_type
00339 vector_map<K, T, C, A>::count(const key_type& x) const
00340 {
00341 return find(x) != end() ? 1 : 0;
00342 }
00343
00344
00345
00346 template <typename K, typename T, typename C, typename A> inline
00347 typename vector_map<K, T, C, A>::iterator
00348 vector_map<K, T, C, A>::lower_bound(const key_type& x)
00349 {
00350 return std::lower_bound(data_.begin(), data_.end(), value_type(x, mapped_type()), value_comp());
00351 }
00352
00353
00354
00355 template <typename K, typename T, typename C, typename A> inline
00356 typename vector_map<K, T, C, A>::const_iterator
00357 vector_map<K, T, C, A>::lower_bound(const key_type& x) const
00358 {
00359 return std::lower_bound(data_.begin(), data_.end(), value_type(x, mapped_type()), value_comp());
00360 }
00361
00362
00363
00364 template <typename K, typename T, typename C, typename A> inline
00365 typename vector_map<K, T, C, A>::iterator
00366 vector_map<K, T, C, A>::upper_bound(const key_type& x)
00367 {
00368 return std::upper_bound(data_.begin(), data_.end(), value_type(x, mapped_type()), value_comp());
00369 }
00370
00371
00372
00373 template <typename K, typename T, typename C, typename A> inline
00374 typename vector_map<K, T, C, A>::const_iterator
00375 vector_map<K, T, C, A>::upper_bound(const key_type& x) const
00376 {
00377 return std::upper_bound(data_.begin(), data_.end(), value_type(x, mapped_type()), value_comp());
00378 }
00379
00380
00381
00382 template <typename K, typename T, typename C, typename A> inline
00383 std::pair<typename vector_map<K, T, C, A>::iterator, typename vector_map<K, T, C, A>::iterator>
00384 vector_map<K, T, C, A>::equal_range(const key_type& x)
00385 {
00386 return std::equal_range(data_.begin(), data_.end(), value_type(x, mapped_type()), value_comp());
00387 }
00388
00389
00390
00391 template <typename K, typename T, typename C, typename A> inline
00392 std::pair<typename vector_map<K, T, C, A>::const_iterator, typename vector_map<K, T, C, A>::const_iterator>
00393 vector_map<K, T, C, A>::equal_range(const key_type& x) const
00394 {
00395 return std::equal_range(data_.begin(), data_.end(), value_type(x, mapped_type()), value_comp());
00396 }
00397
00398
00399
00400
00401
00402
00403
00404 template <typename K, typename T, typename C, typename A>
00405 bool operator==(const vector_map<K, T, C, A>& a, const vector_map<K, T, C, A>& b)
00406 {
00407 return a.size() == b.size() && std::equal(a.begin(), a.end(), b.begin(), a.value_comp());
00408 }
00409
00410
00411
00412
00413
00414 template <typename K, typename T, typename C, typename A> inline
00415 bool operator==(const vector_map<K, T, C, A>& a, const vector_map<K, T, C, A>& b)
00416 {
00417 return !(a == b);
00418 }
00419
00420
00421
00422
00423
00424 template <typename K, typename T, typename C, typename A> inline
00425 bool operator<(const vector_map<K, T, C, A>& a, const vector_map<K, T, C, A>& b)
00426 {
00427 std::lexicographical_compare(a.begin(), a.end(), b.begin, b.end(), a.value_comp());
00428 }
00429
00430
00431
00432
00433
00434 template <typename K, typename T, typename C, typename A> inline
00435 bool operator>(const vector_map<K, T, C, A>& a, const vector_map<K, T, C, A>& b)
00436 {
00437 return b < a
00438 }
00439
00440
00441
00442
00443
00444 template <typename K, typename T, typename C, typename A> inline
00445 bool operator<=(const vector_map<K, T, C, A>& a, const vector_map<K, T, C, A>& b)
00446 {
00447 return !(b < a);
00448 }
00449
00450
00451
00452
00453
00454 template <typename K, typename T, typename C, typename A> inline
00455 bool operator>=(const vector_map<K, T, C, A>& a, const vector_map<K, T, C, A>& b)
00456 {
00457 return !(a < b);
00458 }
00459
00460
00461
00462
00463
00464 template <typename K, typename T, typename C, typename A, typename Char, typename Traits>
00465 std::basic_ostream<Char, Traits>&
00466 operator<<(std::basic_ostream<Char, Traits>& ostream, vector_map<K, T, C, A>& container)
00467 {
00468 return impl::print_map<Char>(ostream, container.begin(), container.end(), "{", ", ", ": ", "}");
00469 }
00470
00471
00472
00473
00474
00475 template <typename Char, typename Traits, typename K, typename T, typename C, typename A>
00476 std::basic_istream<Char, Traits>&
00477 operator>>(std::basic_istream<Char, Traits>& istream, vector_map<K, T, C, A>& container)
00478 {
00479 return impl::read_container<impl::set_traits, impl::pair_traits, std::pair<K, Data>, Char>(
00480 istream, container, '{', ',', ':', '}');
00481 }
00482
00483
00484 }
00485 }
00486
00487 namespace std
00488 {
00489
00490
00491
00492 template <typename Key, typename T, typename Compare, typename Allocator>
00493 void swap(vector_map<Key, T, Compare, Allocator>& a, vector_map<Key, T, Compare, Allocator>& b)
00494 {
00495 a.swap(b);
00496 }
00497
00498 }
00499
00500