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 #ifndef _GLIBCXX_DEBUG_HASH_MULTISET_H
00036 #define _GLIBCXX_DEBUG_HASH_MULTISET_H 1
00037
00038 #include <debug/safe_sequence.h>
00039 #include <debug/safe_iterator.h>
00040
00041 namespace __gnu_cxx
00042 {
00043 namespace __debug
00044 {
00045 template<typename _Value,
00046 typename _HashFcn = __gnu_cxx::hash<_Value>,
00047 typename _EqualKey = std::equal_to<_Value>,
00048 typename _Alloc = std::allocator<_Value> >
00049 class hash_multiset
00050 : public _GLIBCXX_EXT::hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc>,
00051 public __gnu_debug::_Safe_sequence<hash_multiset<_Value, _HashFcn,
00052 _EqualKey, _Alloc> >
00053 {
00054 typedef _GLIBCXX_EXT:: hash_multiset<_Value,_HashFcn, _EqualKey,_Alloc>
00055 _Base;
00056 typedef __gnu_debug::_Safe_sequence<hash_multiset> _Safe_base;
00057
00058 public:
00059 typedef typename _Base::key_type key_type;
00060 typedef typename _Base::value_type value_type;
00061 typedef typename _Base::hasher hasher;
00062 typedef typename _Base::key_equal key_equal;
00063 typedef typename _Base::size_type size_type;
00064 typedef typename _Base::difference_type difference_type;
00065 typedef typename _Base::pointer pointer;
00066 typedef typename _Base::const_pointer const_pointer;
00067 typedef typename _Base::reference reference;
00068 typedef typename _Base::const_reference const_reference;
00069
00070 typedef __gnu_debug::_Safe_iterator<typename _Base::iterator,
00071 hash_multiset> iterator;
00072 typedef __gnu_debug::_Safe_iterator<typename _Base::const_iterator,
00073 hash_multiset> const_iterator;
00074
00075 typedef typename _Base::allocator_type allocator_type;
00076
00077 using _Base::hash_funct;
00078 using _Base::key_eq;
00079 using _Base::get_allocator;
00080
00081 hash_multiset() { }
00082
00083 explicit hash_multiset(size_type __n) : _Base(__n) { }
00084
00085 hash_multiset(size_type __n, const hasher& __hf) : _Base(__n, __hf) { }
00086
00087 hash_multiset(size_type __n, const hasher& __hf, const key_equal& __eql,
00088 const allocator_type& __a = allocator_type())
00089 : _Base(__n, __hf, __eql, __a)
00090 { }
00091
00092 template<typename _InputIterator>
00093 hash_multiset(_InputIterator __f, _InputIterator __l)
00094 : _Base(__gnu_debug::__check_valid_range(__f, __l), __l)
00095 { }
00096
00097 template<typename _InputIterator>
00098 hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n)
00099 : _Base(__gnu_debug::__check_valid_range(__f, __l), __l, __n)
00100 { }
00101
00102 template<typename _InputIterator>
00103 hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n,
00104 const hasher& __hf)
00105 : _Base(__gnu_debug::__check_valid_range(__f, __l), __l, __n, __hf)
00106 { }
00107
00108 template<typename _InputIterator>
00109 hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n,
00110 const hasher& __hf, const key_equal& __eql,
00111 const allocator_type& __a = allocator_type())
00112 : _Base(__gnu_debug::__check_valid_range(__f, __l), __l, __n, __hf,
00113 __eql, __a)
00114 { }
00115
00116 hash_multiset(const _Base& __x) : _Base(__x), _Safe_base() { }
00117
00118 using _Base::size;
00119 using _Base::max_size;
00120 using _Base::empty;
00121
00122 void
00123 swap(hash_multiset& __x)
00124 {
00125 _Base::swap(__x);
00126 this->_M_swap(__x);
00127 }
00128
00129 iterator begin() const { return iterator(_Base::begin(), this); }
00130 iterator end() const { return iterator(_Base::end(), this); }
00131
00132 iterator
00133 insert(const value_type& __obj)
00134 { return iterator(_Base::insert(__obj), this); }
00135
00136 template <typename _InputIterator>
00137 void
00138 insert(_InputIterator __first, _InputIterator __last)
00139 {
00140 __glibcxx_check_valid_range(__first, __last);
00141 _Base::insert(__first.base(), __last.base());
00142 }
00143
00144
00145 iterator
00146 insert_noresize(const value_type& __obj)
00147 { return iterator(_Base::insert_noresize(__obj), this); }
00148
00149 iterator
00150 find(const key_type& __key) const
00151 { return iterator(_Base::find(__key), this); }
00152
00153 using _Base::count;
00154
00155 std::pair<iterator, iterator>
00156 equal_range(const key_type& __key) const
00157 {
00158 typedef typename _Base::iterator _Base_iterator;
00159 std::pair<_Base_iterator, _Base_iterator> __res =
00160 _Base::equal_range(__key);
00161 return std::make_pair(iterator(__res.first, this),
00162 iterator(__res.second, this));
00163 }
00164
00165 size_type
00166 erase(const key_type& __key)
00167 {
00168 size_type __count = 0;
00169 std::pair<iterator, iterator> __victims = this->equal_range(__key);
00170 while (__victims.first != __victims.second)
00171 {
00172 this->erase(__victims++);
00173 ++__count;
00174 }
00175 return __count;
00176 }
00177
00178 void
00179 erase(iterator __it)
00180 {
00181 __glibcxx_check_erase(__it);
00182 __it._M_invalidate();
00183 _Base::erase(__it.base());
00184 }
00185
00186 void
00187 erase(iterator __first, iterator __last)
00188 {
00189 __glibcxx_check_erase_range(__first, __last);
00190 for (iterator __tmp = __first; __tmp != __last;)
00191 {
00192 iterator __victim = __tmp++;
00193 __victim._M_invalidate();
00194 }
00195 _Base::erase(__first.base(), __last.base());
00196 }
00197
00198 void
00199 clear()
00200 {
00201 _Base::clear();
00202 this->_M_invalidate_all();
00203 }
00204
00205 using _Base::resize;
00206 using _Base::bucket_count;
00207 using _Base::max_bucket_count;
00208 using _Base::elems_in_bucket;
00209
00210 _Base& _M_base() { return *this; }
00211 const _Base& _M_base() const { return *this; }
00212
00213 private:
00214 void
00215 _M_invalidate_all()
00216 {
00217 typedef typename _Base::const_iterator _Base_const_iterator;
00218 typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
00219 this->_M_invalidate_if(_Not_equal(_M_base().end()));
00220 }
00221 };
00222
00223 template<typename _Value, typename _HashFcn, typename _EqualKey, typename _Alloc>
00224 inline bool
00225 operator==(const hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc>& __x,
00226 const hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc>& __y)
00227 { return __x._M_base() == __y._M_base(); }
00228
00229 template<typename _Value, typename _HashFcn, typename _EqualKey, typename _Alloc>
00230 inline bool
00231 operator!=(const hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc>& __x,
00232 const hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc>& __y)
00233 { return __x._M_base() != __y._M_base(); }
00234
00235 template<typename _Value, typename _HashFcn, typename _EqualKey, typename _Alloc>
00236 inline void
00237 swap(hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc>& __x,
00238 hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc>& __y)
00239 { __x.swap(__y); }
00240 }
00241 }
00242
00243 #endif