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