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 _CPP_BITS_STL_MAP_H
00062 #define _CPP_BITS_STL_MAP_H 1
00063
00064 #include <bits/concept_check.h>
00065
00066 namespace std
00067 {
00068
00077 template <class _Key, class _Tp, class _Compare = less<_Key>,
00078 class _Alloc = allocator<pair<const _Key, _Tp> > >
00079 class map
00080 {
00081
00082 __glibcpp_class_requires(_Tp, _SGIAssignableConcept)
00083 __glibcpp_class_requires4(_Compare, bool, _Key, _Key, _BinaryFunctionConcept);
00084
00085 public:
00086
00087 typedef _Key key_type;
00088 typedef _Tp data_type;
00089 typedef _Tp mapped_type;
00090 typedef pair<const _Key, _Tp> value_type;
00091 typedef _Compare key_compare;
00092
00093 class value_compare
00094 : public binary_function<value_type, value_type, bool> {
00095 friend class map<_Key,_Tp,_Compare,_Alloc>;
00096 protected :
00097 _Compare comp;
00098 value_compare(_Compare __c) : comp(__c) {}
00099 public:
00100 bool operator()(const value_type& __x, const value_type& __y) const {
00101 return comp(__x.first, __y.first);
00102 }
00103 };
00104
00105 private:
00106 typedef _Rb_tree<key_type, value_type,
00107 _Select1st<value_type>, key_compare, _Alloc> _Rep_type;
00108 _Rep_type _M_t;
00109 public:
00110 typedef typename _Rep_type::pointer pointer;
00111 typedef typename _Rep_type::const_pointer const_pointer;
00112 typedef typename _Rep_type::reference reference;
00113 typedef typename _Rep_type::const_reference const_reference;
00114 typedef typename _Rep_type::iterator iterator;
00115 typedef typename _Rep_type::const_iterator const_iterator;
00116 typedef typename _Rep_type::reverse_iterator reverse_iterator;
00117 typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
00118 typedef typename _Rep_type::size_type size_type;
00119 typedef typename _Rep_type::difference_type difference_type;
00120 typedef typename _Rep_type::allocator_type allocator_type;
00121
00122
00123
00124 map() : _M_t(_Compare(), allocator_type()) {}
00125 explicit map(const _Compare& __comp,
00126 const allocator_type& __a = allocator_type())
00127 : _M_t(__comp, __a) {}
00128
00129 template <class _InputIterator>
00130 map(_InputIterator __first, _InputIterator __last)
00131 : _M_t(_Compare(), allocator_type())
00132 { _M_t.insert_unique(__first, __last); }
00133
00134 template <class _InputIterator>
00135 map(_InputIterator __first, _InputIterator __last, const _Compare& __comp,
00136 const allocator_type& __a = allocator_type())
00137 : _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
00138 map(const map<_Key,_Tp,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {}
00139
00140 map<_Key,_Tp,_Compare,_Alloc>&
00141 operator=(const map<_Key, _Tp, _Compare, _Alloc>& __x)
00142 {
00143 _M_t = __x._M_t;
00144 return *this;
00145 }
00146
00147
00148
00149 key_compare key_comp() const { return _M_t.key_comp(); }
00150 value_compare value_comp() const { return value_compare(_M_t.key_comp()); }
00151 allocator_type get_allocator() const { return _M_t.get_allocator(); }
00152
00157 iterator begin() { return _M_t.begin(); }
00158
00163 const_iterator begin() const { return _M_t.begin(); }
00164
00169 iterator end() { return _M_t.end(); }
00170
00176 const_iterator end() const { return _M_t.end(); }
00177
00182 reverse_iterator rbegin() { return _M_t.rbegin(); }
00183
00189 const_reverse_iterator rbegin() const { return _M_t.rbegin(); }
00190
00196 reverse_iterator rend() { return _M_t.rend(); }
00197
00203 const_reverse_iterator rend() const { return _M_t.rend(); }
00204
00206 bool empty() const { return _M_t.empty(); }
00208 size_type size() const { return _M_t.size(); }
00210 size_type max_size() const { return _M_t.max_size(); }
00211
00221 _Tp& operator[](const key_type& __k) {
00222 iterator __i = lower_bound(__k);
00223
00224 if (__i == end() || key_comp()(__k, (*__i).first))
00225 __i = insert(__i, value_type(__k, _Tp()));
00226 return (*__i).second;
00227 }
00228
00229 void swap(map<_Key,_Tp,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
00230
00231
00244 pair<iterator,bool> insert(const value_type& __x)
00245 { return _M_t.insert_unique(__x); }
00246
00261 iterator insert(iterator position, const value_type& __x)
00262 { return _M_t.insert_unique(position, __x); }
00263
00270 template <class _InputIterator>
00271 void insert(_InputIterator __first, _InputIterator __last) {
00272 _M_t.insert_unique(__first, __last);
00273 }
00274
00284 void erase(iterator __position) { _M_t.erase(__position); }
00285
00297 size_type erase(const key_type& __x) { return _M_t.erase(__x); }
00298
00309 void erase(iterator __first, iterator __last)
00310 { _M_t.erase(__first, __last); }
00311
00317 void clear() { _M_t.clear(); }
00318
00319
00320
00332 iterator find(const key_type& __x) { return _M_t.find(__x); }
00333
00345 const_iterator find(const key_type& __x) const { return _M_t.find(__x); }
00346
00354 size_type count(const key_type& __x) const {
00355 return _M_t.find(__x) == _M_t.end() ? 0 : 1;
00356 }
00357
00369 iterator lower_bound(const key_type& __x) {return _M_t.lower_bound(__x); }
00370
00382 const_iterator lower_bound(const key_type& __x) const {
00383 return _M_t.lower_bound(__x);
00384 }
00385
00393 iterator upper_bound(const key_type& __x) {return _M_t.upper_bound(__x); }
00394
00403 const_iterator upper_bound(const key_type& __x) const {
00404 return _M_t.upper_bound(__x);
00405 }
00406
00423 pair<iterator,iterator> equal_range(const key_type& __x) {
00424 return _M_t.equal_range(__x);
00425 }
00426
00443 pair<const_iterator,const_iterator> equal_range(const key_type& __x) const {
00444 return _M_t.equal_range(__x);
00445 }
00446
00447 template <class _K1, class _T1, class _C1, class _A1>
00448 friend bool operator== (const map<_K1, _T1, _C1, _A1>&,
00449 const map<_K1, _T1, _C1, _A1>&);
00450 template <class _K1, class _T1, class _C1, class _A1>
00451 friend bool operator< (const map<_K1, _T1, _C1, _A1>&,
00452 const map<_K1, _T1, _C1, _A1>&);
00453 };
00454
00455 template <class _Key, class _Tp, class _Compare, class _Alloc>
00456 inline bool operator==(const map<_Key,_Tp,_Compare,_Alloc>& __x,
00457 const map<_Key,_Tp,_Compare,_Alloc>& __y) {
00458 return __x._M_t == __y._M_t;
00459 }
00460
00461 template <class _Key, class _Tp, class _Compare, class _Alloc>
00462 inline bool operator<(const map<_Key,_Tp,_Compare,_Alloc>& __x,
00463 const map<_Key,_Tp,_Compare,_Alloc>& __y) {
00464 return __x._M_t < __y._M_t;
00465 }
00466
00467 template <class _Key, class _Tp, class _Compare, class _Alloc>
00468 inline bool operator!=(const map<_Key,_Tp,_Compare,_Alloc>& __x,
00469 const map<_Key,_Tp,_Compare,_Alloc>& __y) {
00470 return !(__x == __y);
00471 }
00472
00473 template <class _Key, class _Tp, class _Compare, class _Alloc>
00474 inline bool operator>(const map<_Key,_Tp,_Compare,_Alloc>& __x,
00475 const map<_Key,_Tp,_Compare,_Alloc>& __y) {
00476 return __y < __x;
00477 }
00478
00479 template <class _Key, class _Tp, class _Compare, class _Alloc>
00480 inline bool operator<=(const map<_Key,_Tp,_Compare,_Alloc>& __x,
00481 const map<_Key,_Tp,_Compare,_Alloc>& __y) {
00482 return !(__y < __x);
00483 }
00484
00485 template <class _Key, class _Tp, class _Compare, class _Alloc>
00486 inline bool operator>=(const map<_Key,_Tp,_Compare,_Alloc>& __x,
00487 const map<_Key,_Tp,_Compare,_Alloc>& __y) {
00488 return !(__x < __y);
00489 }
00490
00491 template <class _Key, class _Tp, class _Compare, class _Alloc>
00492 inline void swap(map<_Key,_Tp,_Compare,_Alloc>& __x,
00493 map<_Key,_Tp,_Compare,_Alloc>& __y) {
00494 __x.swap(__y);
00495 }
00496
00497 }
00498
00499 #endif
00500
00501
00502
00503