]>
Commit | Line | Data |
---|---|---|
285b36d6 BK |
1 | // Debugging hash_multiset implementation -*- C++ -*- |
2 | ||
3cbc7af0 | 3 | // Copyright (C) 2003, 2005 |
285b36d6 BK |
4 | // Free Software Foundation, Inc. |
5 | // | |
6 | // This file is part of the GNU ISO C++ Library. This library is free | |
7 | // software; you can redistribute it and/or modify it under the | |
8 | // terms of the GNU General Public License as published by the | |
9 | // Free Software Foundation; either version 2, or (at your option) | |
10 | // any later version. | |
11 | ||
12 | // This library is distributed in the hope that it will be useful, | |
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | // GNU General Public License for more details. | |
16 | ||
17 | // You should have received a copy of the GNU General Public License along | |
18 | // with this library; see the file COPYING. If not, write to the Free | |
83f51799 | 19 | // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
285b36d6 BK |
20 | // USA. |
21 | ||
22 | // As a special exception, you may use this file as part of a free software | |
23 | // library without restriction. Specifically, if other files instantiate | |
24 | // templates or use macros or inline functions from this file, or you compile | |
25 | // this file and link it with other files to produce an executable, this | |
26 | // file does not by itself cause the resulting executable to be covered by | |
27 | // the GNU General Public License. This exception does not however | |
28 | // invalidate any other reasons why the executable file might be covered by | |
29 | // the GNU General Public License. | |
30 | ||
31 | #ifndef _GLIBCXX_DEBUG_HASH_MULTISET_H | |
32 | #define _GLIBCXX_DEBUG_HASH_MULTISET_H 1 | |
33 | ||
34 | #include <debug/safe_sequence.h> | |
35 | #include <debug/safe_iterator.h> | |
36 | ||
3cbc7af0 BK |
37 | namespace std |
38 | { | |
285b36d6 BK |
39 | namespace __gnu_debug_def |
40 | { | |
41 | template<typename _Value, | |
42 | typename _HashFcn = __gnu_cxx::hash<_Value>, | |
43 | typename _EqualKey = std::equal_to<_Value>, | |
44 | typename _Alloc = std::allocator<_Value> > | |
45 | class hash_multiset | |
46 | : public __gnu_cxx::hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc>, | |
47 | public __gnu_debug::_Safe_sequence<hash_multiset<_Value, _HashFcn, | |
48 | _EqualKey, _Alloc> > | |
49 | { | |
50 | typedef __gnu_cxx:: hash_multiset<_Value,_HashFcn, _EqualKey,_Alloc> | |
526da49c | 51 | _Base; |
285b36d6 BK |
52 | typedef __gnu_debug::_Safe_sequence<hash_multiset> _Safe_base; |
53 | ||
54 | public: | |
526da49c BI |
55 | typedef typename _Base::key_type key_type; |
56 | typedef typename _Base::value_type value_type; | |
57 | typedef typename _Base::hasher hasher; | |
58 | typedef typename _Base::key_equal key_equal; | |
59 | typedef typename _Base::size_type size_type; | |
60 | typedef typename _Base::difference_type difference_type; | |
61 | typedef typename _Base::pointer pointer; | |
62 | typedef typename _Base::const_pointer const_pointer; | |
63 | typedef typename _Base::reference reference; | |
64 | typedef typename _Base::const_reference const_reference; | |
65 | ||
66 | typedef __gnu_debug::_Safe_iterator<typename _Base::iterator, | |
285b36d6 BK |
67 | hash_multiset> iterator; |
68 | typedef __gnu_debug::_Safe_iterator<typename _Base::const_iterator, | |
69 | hash_multiset> const_iterator; | |
70 | ||
71 | typedef typename _Base::allocator_type allocator_type; | |
72 | ||
73 | using _Base::hash_funct; | |
74 | using _Base::key_eq; | |
75 | using _Base::get_allocator; | |
76 | ||
77 | hash_multiset() { } | |
78 | ||
79 | explicit hash_multiset(size_type __n) : _Base(__n) { } | |
80 | ||
81 | hash_multiset(size_type __n, const hasher& __hf) : _Base(__n, __hf) { } | |
82 | ||
83 | hash_multiset(size_type __n, const hasher& __hf, const key_equal& __eql, | |
84 | const allocator_type& __a = allocator_type()) | |
85 | : _Base(__n, __hf, __eql, __a) | |
86 | { } | |
526da49c | 87 | |
285b36d6 BK |
88 | template<typename _InputIterator> |
89 | hash_multiset(_InputIterator __f, _InputIterator __l) | |
90 | : _Base(__gnu_debug::__check_valid_range(__f, __l), __l) | |
91 | { } | |
92 | ||
93 | template<typename _InputIterator> | |
94 | hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n) | |
95 | : _Base(__gnu_debug::__check_valid_range(__f, __l), __l, __n) | |
96 | { } | |
97 | ||
98 | template<typename _InputIterator> | |
99 | hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n, | |
100 | const hasher& __hf) | |
101 | : _Base(__gnu_debug::__check_valid_range(__f, __l), __l, __n, __hf) | |
102 | { } | |
103 | ||
104 | template<typename _InputIterator> | |
105 | hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n, | |
106 | const hasher& __hf, const key_equal& __eql, | |
107 | const allocator_type& __a = allocator_type()) | |
108 | : _Base(__gnu_debug::__check_valid_range(__f, __l), __l, __n, __hf, | |
109 | __eql, __a) | |
110 | { } | |
111 | ||
112 | hash_multiset(const _Base& __x) : _Base(__x), _Safe_base() { } | |
113 | ||
114 | using _Base::size; | |
115 | using _Base::max_size; | |
116 | using _Base::empty; | |
117 | ||
526da49c | 118 | void |
285b36d6 BK |
119 | swap(hash_multiset& __x) |
120 | { | |
121 | _Base::swap(__x); | |
122 | this->_M_swap(__x); | |
123 | } | |
124 | ||
125 | iterator begin() const { return iterator(_Base::begin(), this); } | |
126 | iterator end() const { return iterator(_Base::end(), this); } | |
127 | ||
128 | iterator | |
129 | insert(const value_type& __obj) | |
130 | { return iterator(_Base::insert(__obj), this); } | |
131 | ||
132 | template <typename _InputIterator> | |
526da49c BI |
133 | void |
134 | insert(_InputIterator __first, _InputIterator __last) | |
285b36d6 BK |
135 | { |
136 | __glibcxx_check_valid_range(__first, __last); | |
137 | _Base::insert(__first.base(), __last.base()); | |
138 | } | |
139 | ||
140 | ||
141 | iterator | |
142 | insert_noresize(const value_type& __obj) | |
143 | { return iterator(_Base::insert_noresize(__obj), this); } | |
144 | ||
526da49c BI |
145 | iterator |
146 | find(const key_type& __key) const | |
285b36d6 BK |
147 | { return iterator(_Base::find(__key), this); } |
148 | ||
149 | using _Base::count; | |
526da49c BI |
150 | |
151 | std::pair<iterator, iterator> | |
285b36d6 | 152 | equal_range(const key_type& __key) const |
526da49c | 153 | { |
285b36d6 | 154 | typedef typename _Base::iterator _Base_iterator; |
526da49c | 155 | std::pair<_Base_iterator, _Base_iterator> __res = |
285b36d6 BK |
156 | _Base::equal_range(__key); |
157 | return std::make_pair(iterator(__res.first, this), | |
158 | iterator(__res.second, this)); | |
159 | } | |
160 | ||
526da49c BI |
161 | size_type |
162 | erase(const key_type& __key) | |
285b36d6 BK |
163 | { |
164 | size_type __count = 0; | |
165 | std::pair<iterator, iterator> __victims = this->equal_range(__key); | |
166 | while (__victims.first != __victims.second) | |
167 | { | |
168 | this->erase(__victims++); | |
169 | ++__count; | |
170 | } | |
171 | return __count; | |
172 | } | |
526da49c BI |
173 | |
174 | void | |
175 | erase(iterator __it) | |
285b36d6 BK |
176 | { |
177 | __glibcxx_check_erase(__it); | |
178 | __it._M_invalidate(); | |
179 | _Base::erase(__it.base()); | |
180 | } | |
181 | ||
526da49c | 182 | void |
285b36d6 BK |
183 | erase(iterator __first, iterator __last) |
184 | { | |
185 | __glibcxx_check_erase_range(__first, __last); | |
186 | for (iterator __tmp = __first; __tmp != __last;) | |
187 | { | |
188 | iterator __victim = __tmp++; | |
189 | __victim._M_invalidate(); | |
190 | } | |
191 | _Base::erase(__first.base(), __last.base()); | |
192 | } | |
193 | ||
526da49c BI |
194 | void |
195 | clear() | |
196 | { | |
285b36d6 | 197 | _Base::clear(); |
526da49c | 198 | this->_M_invalidate_all(); |
285b36d6 BK |
199 | } |
200 | ||
201 | using _Base::resize; | |
202 | using _Base::bucket_count; | |
203 | using _Base::max_bucket_count; | |
204 | using _Base::elems_in_bucket; | |
205 | ||
206 | _Base& _M_base() { return *this; } | |
207 | const _Base& _M_base() const { return *this; } | |
208 | ||
209 | private: | |
526da49c | 210 | void |
285b36d6 BK |
211 | _M_invalidate_all() |
212 | { | |
213 | typedef typename _Base::const_iterator _Base_const_iterator; | |
214 | typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal; | |
215 | this->_M_invalidate_if(_Not_equal(_M_base().end())); | |
216 | } | |
217 | }; | |
218 | ||
219 | template<typename _Value, typename _HashFcn, typename _EqualKey, typename _Alloc> | |
220 | inline bool | |
221 | operator==(const hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc>& __x, | |
222 | const hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc>& __y) | |
223 | { return __x._M_base() == __y._M_base(); } | |
224 | ||
225 | template<typename _Value, typename _HashFcn, typename _EqualKey, typename _Alloc> | |
226 | inline bool | |
227 | operator!=(const hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc>& __x, | |
228 | const hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc>& __y) | |
229 | { return __x._M_base() != __y._M_base(); } | |
230 | ||
231 | template<typename _Value, typename _HashFcn, typename _EqualKey, typename _Alloc> | |
232 | inline void | |
233 | swap(hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc>& __x, | |
234 | hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc>& __y) | |
235 | { __x.swap(__y); } | |
236 | } // namespace __gnu_debug_def | |
3cbc7af0 | 237 | } // namespace std |
285b36d6 BK |
238 | |
239 | #endif |