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
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00061 #ifndef __GLIBCPP_INTERNAL_MAP_H
00062 #define __GLIBCPP_INTERNAL_MAP_H
00063
00064 #include <bits/concept_check.h>
00065
00066 namespace std
00067 {
00089 template <typename _Key, typename _Tp, typename _Compare = less<_Key>,
00090 typename _Alloc = allocator<pair<const _Key, _Tp> > >
00091 class map
00092 {
00093
00094 __glibcpp_class_requires(_Tp, _SGIAssignableConcept)
00095 __glibcpp_class_requires4(_Compare, bool, _Key, _Key, _BinaryFunctionConcept)
00096
00097 public:
00098 typedef _Key key_type;
00099 typedef _Tp mapped_type;
00100 typedef pair<const _Key, _Tp> value_type;
00101 typedef _Compare key_compare;
00102
00103 class value_compare
00104 : public binary_function<value_type, value_type, bool>
00105 {
00106 friend class map<_Key,_Tp,_Compare,_Alloc>;
00107 protected:
00108 _Compare comp;
00109 value_compare(_Compare __c) : comp(__c) {}
00110 public:
00111 bool operator()(const value_type& __x, const value_type& __y) const
00112 { return comp(__x.first, __y.first); }
00113 };
00114
00115 private:
00117 typedef _Rb_tree<key_type, value_type,
00118 _Select1st<value_type>, key_compare, _Alloc> _Rep_type;
00120 _Rep_type _M_t;
00121
00122 public:
00123
00124
00125 typedef typename _Rep_type::allocator_type allocator_type;
00126 typedef typename _Rep_type::reference reference;
00127 typedef typename _Rep_type::const_reference const_reference;
00128 typedef typename _Rep_type::iterator iterator;
00129 typedef typename _Rep_type::const_iterator const_iterator;
00130 typedef typename _Rep_type::size_type size_type;
00131 typedef typename _Rep_type::difference_type difference_type;
00132 typedef typename _Rep_type::pointer pointer;
00133 typedef typename _Rep_type::const_pointer const_pointer;
00134 typedef typename _Rep_type::reverse_iterator reverse_iterator;
00135 typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
00136
00137
00138
00139
00140
00144 map() : _M_t(_Compare(), allocator_type()) { }
00145
00146
00150 explicit
00151 map(const _Compare& __comp, const allocator_type& __a = allocator_type())
00152 : _M_t(__comp, __a) { }
00153
00161 map(const map& __x)
00162 : _M_t(__x._M_t) { }
00163
00173 template <typename _InputIterator>
00174 map(_InputIterator __first, _InputIterator __last)
00175 : _M_t(_Compare(), allocator_type())
00176 { _M_t.insert_unique(__first, __last); }
00177
00189 template <typename _InputIterator>
00190 map(_InputIterator __first, _InputIterator __last,
00191 const _Compare& __comp, const allocator_type& __a = allocator_type())
00192 : _M_t(__comp, __a)
00193 { _M_t.insert_unique(__first, __last); }
00194
00195
00196
00197
00211 map&
00212 operator=(const map& __x)
00213 {
00214 _M_t = __x._M_t;
00215 return *this;
00216 }
00217
00219 allocator_type
00220 get_allocator() const { return _M_t.get_allocator(); }
00221
00222
00227 iterator
00228 begin() { return _M_t.begin(); }
00229
00235 const_iterator
00236 begin() const { return _M_t.begin(); }
00237
00242 iterator
00243 end() { return _M_t.end(); }
00244
00250 const_iterator
00251 end() const { return _M_t.end(); }
00252
00257 reverse_iterator
00258 rbegin() { return _M_t.rbegin(); }
00259
00265 const_reverse_iterator
00266 rbegin() const { return _M_t.rbegin(); }
00267
00273 reverse_iterator
00274 rend() { return _M_t.rend(); }
00275
00281 const_reverse_iterator
00282 rend() const { return _M_t.rend(); }
00283
00284
00286 bool
00287 empty() const { return _M_t.empty(); }
00288
00290 size_type
00291 size() const { return _M_t.size(); }
00292
00294 size_type
00295 max_size() const { return _M_t.max_size(); }
00296
00297
00310 mapped_type&
00311 operator[](const key_type& __k)
00312 {
00313
00314 __glibcpp_function_requires(_DefaultConstructibleConcept<mapped_type>)
00315
00316 iterator __i = lower_bound(__k);
00317
00318 if (__i == end() || key_comp()(__k, (*__i).first))
00319 __i = insert(__i, value_type(__k, mapped_type()));
00320 return (*__i).second;
00321 }
00322
00323
00338 pair<iterator,bool>
00339 insert(const value_type& __x)
00340 { return _M_t.insert_unique(__x); }
00341
00362 iterator
00363 insert(iterator position, const value_type& __x)
00364 { return _M_t.insert_unique(position, __x); }
00365
00374 template <typename _InputIterator>
00375 void
00376 insert(_InputIterator __first, _InputIterator __last)
00377 { _M_t.insert_unique(__first, __last); }
00378
00388 void
00389 erase(iterator __position) { _M_t.erase(__position); }
00390
00402 size_type
00403 erase(const key_type& __x) { return _M_t.erase(__x); }
00404
00415 void
00416 erase(iterator __first, iterator __last) { _M_t.erase(__first, __last); }
00417
00429 void
00430 swap(map& __x) { _M_t.swap(__x._M_t); }
00431
00438 void
00439 clear() { _M_t.clear(); }
00440
00441
00445 key_compare
00446 key_comp() const { return _M_t.key_comp(); }
00447
00452 value_compare
00453 value_comp() const { return value_compare(_M_t.key_comp()); }
00454
00455
00467 iterator
00468 find(const key_type& __x) { return _M_t.find(__x); }
00469
00481 const_iterator
00482 find(const key_type& __x) const { return _M_t.find(__x); }
00483
00492 size_type
00493 count(const key_type& __x) const
00494 { return _M_t.find(__x) == _M_t.end() ? 0 : 1; }
00495
00507 iterator
00508 lower_bound(const key_type& __x) { return _M_t.lower_bound(__x); }
00509
00521 const_iterator
00522 lower_bound(const key_type& __x) const { return _M_t.lower_bound(__x); }
00523
00531 iterator
00532 upper_bound(const key_type& __x) { return _M_t.upper_bound(__x); }
00533
00542 const_iterator
00543 upper_bound(const key_type& __x) const
00544 { return _M_t.upper_bound(__x); }
00545
00561 pair<iterator,iterator>
00562 equal_range(const key_type& __x)
00563 { return _M_t.equal_range(__x); }
00564
00580 pair<const_iterator,const_iterator>
00581 equal_range(const key_type& __x) const
00582 { return _M_t.equal_range(__x); }
00583
00584 template <typename _K1, typename _T1, typename _C1, typename _A1>
00585 friend bool operator== (const map<_K1,_T1,_C1,_A1>&,
00586 const map<_K1,_T1,_C1,_A1>&);
00587 template <typename _K1, typename _T1, typename _C1, typename _A1>
00588 friend bool operator< (const map<_K1,_T1,_C1,_A1>&,
00589 const map<_K1,_T1,_C1,_A1>&);
00590 };
00591
00592
00603 template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00604 inline bool
00605 operator==(const map<_Key,_Tp,_Compare,_Alloc>& __x,
00606 const map<_Key,_Tp,_Compare,_Alloc>& __y)
00607 { return __x._M_t == __y._M_t; }
00608
00620 template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00621 inline bool
00622 operator<(const map<_Key,_Tp,_Compare,_Alloc>& __x,
00623 const map<_Key,_Tp,_Compare,_Alloc>& __y)
00624 { return __x._M_t < __y._M_t; }
00625
00627 template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00628 inline bool
00629 operator!=(const map<_Key,_Tp,_Compare,_Alloc>& __x,
00630 const map<_Key,_Tp,_Compare,_Alloc>& __y)
00631 { return !(__x == __y); }
00632
00634 template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00635 inline bool
00636 operator>(const map<_Key,_Tp,_Compare,_Alloc>& __x,
00637 const map<_Key,_Tp,_Compare,_Alloc>& __y)
00638 { return __y < __x; }
00639
00641 template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00642 inline bool
00643 operator<=(const map<_Key,_Tp,_Compare,_Alloc>& __x,
00644 const map<_Key,_Tp,_Compare,_Alloc>& __y)
00645 { return !(__y < __x); }
00646
00648 template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00649 inline bool
00650 operator>=(const map<_Key,_Tp,_Compare,_Alloc>& __x,
00651 const map<_Key,_Tp,_Compare,_Alloc>& __y)
00652 { return !(__x < __y); }
00653
00655 template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00656 inline void
00657 swap(map<_Key,_Tp,_Compare,_Alloc>& __x, map<_Key,_Tp,_Compare,_Alloc>& __y)
00658 { __x.swap(__y); }
00659 }
00660
00661 #endif