1132720Skan// Debugging hash_multiset implementation -*- C++ -*- 2132720Skan 3169691Skan// Copyright (C) 2003, 2005, 2006 4132720Skan// Free Software Foundation, Inc. 5132720Skan// 6132720Skan// This file is part of the GNU ISO C++ Library. This library is free 7132720Skan// software; you can redistribute it and/or modify it under the 8132720Skan// terms of the GNU General Public License as published by the 9132720Skan// Free Software Foundation; either version 2, or (at your option) 10132720Skan// any later version. 11132720Skan 12132720Skan// This library is distributed in the hope that it will be useful, 13132720Skan// but WITHOUT ANY WARRANTY; without even the implied warranty of 14132720Skan// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15132720Skan// GNU General Public License for more details. 16132720Skan 17132720Skan// You should have received a copy of the GNU General Public License along 18132720Skan// with this library; see the file COPYING. If not, write to the Free 19169691Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 20132720Skan// USA. 21132720Skan 22132720Skan// As a special exception, you may use this file as part of a free software 23132720Skan// library without restriction. Specifically, if other files instantiate 24132720Skan// templates or use macros or inline functions from this file, or you compile 25132720Skan// this file and link it with other files to produce an executable, this 26132720Skan// file does not by itself cause the resulting executable to be covered by 27132720Skan// the GNU General Public License. This exception does not however 28132720Skan// invalidate any other reasons why the executable file might be covered by 29132720Skan// the GNU General Public License. 30132720Skan 31169691Skan/** @file debug/hash_multiset.h 32169691Skan * This file is a GNU debug extension to the Standard C++ Library. 33169691Skan */ 34169691Skan 35132720Skan#ifndef _GLIBCXX_DEBUG_HASH_MULTISET_H 36132720Skan#define _GLIBCXX_DEBUG_HASH_MULTISET_H 1 37132720Skan 38132720Skan#include <debug/safe_sequence.h> 39132720Skan#include <debug/safe_iterator.h> 40132720Skan 41169691Skannamespace __gnu_cxx 42132720Skan{ 43169691Skannamespace __debug 44169691Skan{ 45132720Skan template<typename _Value, 46132720Skan typename _HashFcn = __gnu_cxx::hash<_Value>, 47132720Skan typename _EqualKey = std::equal_to<_Value>, 48132720Skan typename _Alloc = std::allocator<_Value> > 49132720Skan class hash_multiset 50169691Skan : public _GLIBCXX_EXT::hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc>, 51132720Skan public __gnu_debug::_Safe_sequence<hash_multiset<_Value, _HashFcn, 52132720Skan _EqualKey, _Alloc> > 53132720Skan { 54169691Skan typedef _GLIBCXX_EXT:: hash_multiset<_Value,_HashFcn, _EqualKey,_Alloc> 55132720Skan _Base; 56132720Skan typedef __gnu_debug::_Safe_sequence<hash_multiset> _Safe_base; 57132720Skan 58132720Skan public: 59132720Skan typedef typename _Base::key_type key_type; 60132720Skan typedef typename _Base::value_type value_type; 61132720Skan typedef typename _Base::hasher hasher; 62132720Skan typedef typename _Base::key_equal key_equal; 63132720Skan typedef typename _Base::size_type size_type; 64132720Skan typedef typename _Base::difference_type difference_type; 65132720Skan typedef typename _Base::pointer pointer; 66132720Skan typedef typename _Base::const_pointer const_pointer; 67132720Skan typedef typename _Base::reference reference; 68132720Skan typedef typename _Base::const_reference const_reference; 69132720Skan 70132720Skan typedef __gnu_debug::_Safe_iterator<typename _Base::iterator, 71132720Skan hash_multiset> iterator; 72132720Skan typedef __gnu_debug::_Safe_iterator<typename _Base::const_iterator, 73132720Skan hash_multiset> const_iterator; 74132720Skan 75132720Skan typedef typename _Base::allocator_type allocator_type; 76132720Skan 77132720Skan using _Base::hash_funct; 78132720Skan using _Base::key_eq; 79132720Skan using _Base::get_allocator; 80132720Skan 81132720Skan hash_multiset() { } 82132720Skan 83132720Skan explicit hash_multiset(size_type __n) : _Base(__n) { } 84132720Skan 85132720Skan hash_multiset(size_type __n, const hasher& __hf) : _Base(__n, __hf) { } 86132720Skan 87132720Skan hash_multiset(size_type __n, const hasher& __hf, const key_equal& __eql, 88132720Skan const allocator_type& __a = allocator_type()) 89132720Skan : _Base(__n, __hf, __eql, __a) 90132720Skan { } 91132720Skan 92132720Skan template<typename _InputIterator> 93132720Skan hash_multiset(_InputIterator __f, _InputIterator __l) 94132720Skan : _Base(__gnu_debug::__check_valid_range(__f, __l), __l) 95132720Skan { } 96132720Skan 97132720Skan template<typename _InputIterator> 98132720Skan hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n) 99132720Skan : _Base(__gnu_debug::__check_valid_range(__f, __l), __l, __n) 100132720Skan { } 101132720Skan 102132720Skan template<typename _InputIterator> 103132720Skan hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n, 104132720Skan const hasher& __hf) 105132720Skan : _Base(__gnu_debug::__check_valid_range(__f, __l), __l, __n, __hf) 106132720Skan { } 107132720Skan 108132720Skan template<typename _InputIterator> 109132720Skan hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n, 110132720Skan const hasher& __hf, const key_equal& __eql, 111132720Skan const allocator_type& __a = allocator_type()) 112132720Skan : _Base(__gnu_debug::__check_valid_range(__f, __l), __l, __n, __hf, 113132720Skan __eql, __a) 114132720Skan { } 115132720Skan 116132720Skan hash_multiset(const _Base& __x) : _Base(__x), _Safe_base() { } 117132720Skan 118132720Skan using _Base::size; 119132720Skan using _Base::max_size; 120132720Skan using _Base::empty; 121132720Skan 122132720Skan void 123132720Skan swap(hash_multiset& __x) 124132720Skan { 125132720Skan _Base::swap(__x); 126132720Skan this->_M_swap(__x); 127132720Skan } 128132720Skan 129132720Skan iterator begin() const { return iterator(_Base::begin(), this); } 130132720Skan iterator end() const { return iterator(_Base::end(), this); } 131132720Skan 132132720Skan iterator 133132720Skan insert(const value_type& __obj) 134132720Skan { return iterator(_Base::insert(__obj), this); } 135132720Skan 136132720Skan template <typename _InputIterator> 137132720Skan void 138132720Skan insert(_InputIterator __first, _InputIterator __last) 139132720Skan { 140132720Skan __glibcxx_check_valid_range(__first, __last); 141132720Skan _Base::insert(__first.base(), __last.base()); 142132720Skan } 143132720Skan 144132720Skan 145132720Skan iterator 146132720Skan insert_noresize(const value_type& __obj) 147132720Skan { return iterator(_Base::insert_noresize(__obj), this); } 148132720Skan 149132720Skan iterator 150132720Skan find(const key_type& __key) const 151132720Skan { return iterator(_Base::find(__key), this); } 152132720Skan 153132720Skan using _Base::count; 154132720Skan 155132720Skan std::pair<iterator, iterator> 156132720Skan equal_range(const key_type& __key) const 157132720Skan { 158132720Skan typedef typename _Base::iterator _Base_iterator; 159132720Skan std::pair<_Base_iterator, _Base_iterator> __res = 160132720Skan _Base::equal_range(__key); 161132720Skan return std::make_pair(iterator(__res.first, this), 162132720Skan iterator(__res.second, this)); 163132720Skan } 164132720Skan 165132720Skan size_type 166132720Skan erase(const key_type& __key) 167132720Skan { 168132720Skan size_type __count = 0; 169132720Skan std::pair<iterator, iterator> __victims = this->equal_range(__key); 170132720Skan while (__victims.first != __victims.second) 171132720Skan { 172132720Skan this->erase(__victims++); 173132720Skan ++__count; 174132720Skan } 175132720Skan return __count; 176132720Skan } 177132720Skan 178132720Skan void 179132720Skan erase(iterator __it) 180132720Skan { 181132720Skan __glibcxx_check_erase(__it); 182132720Skan __it._M_invalidate(); 183132720Skan _Base::erase(__it.base()); 184132720Skan } 185132720Skan 186132720Skan void 187132720Skan erase(iterator __first, iterator __last) 188132720Skan { 189132720Skan __glibcxx_check_erase_range(__first, __last); 190132720Skan for (iterator __tmp = __first; __tmp != __last;) 191132720Skan { 192132720Skan iterator __victim = __tmp++; 193132720Skan __victim._M_invalidate(); 194132720Skan } 195132720Skan _Base::erase(__first.base(), __last.base()); 196132720Skan } 197132720Skan 198132720Skan void 199132720Skan clear() 200132720Skan { 201132720Skan _Base::clear(); 202132720Skan this->_M_invalidate_all(); 203132720Skan } 204132720Skan 205132720Skan using _Base::resize; 206132720Skan using _Base::bucket_count; 207132720Skan using _Base::max_bucket_count; 208132720Skan using _Base::elems_in_bucket; 209132720Skan 210132720Skan _Base& _M_base() { return *this; } 211132720Skan const _Base& _M_base() const { return *this; } 212132720Skan 213132720Skan private: 214132720Skan void 215132720Skan _M_invalidate_all() 216132720Skan { 217132720Skan typedef typename _Base::const_iterator _Base_const_iterator; 218132720Skan typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal; 219132720Skan this->_M_invalidate_if(_Not_equal(_M_base().end())); 220132720Skan } 221132720Skan }; 222132720Skan 223132720Skantemplate<typename _Value, typename _HashFcn, typename _EqualKey, typename _Alloc> 224132720Skan inline bool 225132720Skan operator==(const hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc>& __x, 226132720Skan const hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc>& __y) 227132720Skan { return __x._M_base() == __y._M_base(); } 228132720Skan 229132720Skantemplate<typename _Value, typename _HashFcn, typename _EqualKey, typename _Alloc> 230132720Skan inline bool 231132720Skan operator!=(const hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc>& __x, 232132720Skan const hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc>& __y) 233132720Skan { return __x._M_base() != __y._M_base(); } 234132720Skan 235132720Skantemplate<typename _Value, typename _HashFcn, typename _EqualKey, typename _Alloc> 236132720Skan inline void 237132720Skan swap(hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc>& __x, 238132720Skan hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc>& __y) 239132720Skan { __x.swap(__y); } 240169691Skan} // namespace __debug 241169691Skan} // namespace __gnu_cxx 242132720Skan 243132720Skan#endif 244