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