1132720Skan// Debugging hash_set 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_set.h 32169691Skan * This file is a GNU debug extension to the Standard C++ Library. 33169691Skan */ 34169691Skan 35132720Skan#ifndef _GLIBCXX_DEBUG_HASH_SET_H 36132720Skan#define _GLIBCXX_DEBUG_HASH_SET_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_set 50169691Skan : public _GLIBCXX_EXT::hash_set<_Value, _HashFcn, _EqualKey,_Alloc>, 51132720Skan public __gnu_debug::_Safe_sequence<hash_set<_Value, _HashFcn, _EqualKey, 52132720Skan _Alloc> > 53132720Skan { 54169691Skan typedef _GLIBCXX_EXT::hash_set<_Value, _HashFcn, _EqualKey,_Alloc> _Base; 55132720Skan typedef __gnu_debug::_Safe_sequence<hash_set> _Safe_base; 56132720Skan 57132720Skan public: 58132720Skan typedef typename _Base::key_type key_type; 59132720Skan typedef typename _Base::value_type value_type; 60132720Skan typedef typename _Base::hasher hasher; 61132720Skan typedef typename _Base::key_equal key_equal; 62132720Skan typedef typename _Base::size_type size_type; 63132720Skan typedef typename _Base::difference_type difference_type; 64132720Skan typedef typename _Base::pointer pointer; 65132720Skan typedef typename _Base::const_pointer const_pointer; 66132720Skan typedef typename _Base::reference reference; 67132720Skan typedef typename _Base::const_reference const_reference; 68132720Skan 69132720Skan typedef __gnu_debug::_Safe_iterator<typename _Base::iterator, hash_set> 70132720Skan iterator; 71132720Skan typedef __gnu_debug::_Safe_iterator<typename _Base::const_iterator, 72132720Skan hash_set> 73132720Skan 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_set() { } 82132720Skan 83132720Skan explicit hash_set(size_type __n) : _Base(__n) { } 84132720Skan 85132720Skan hash_set(size_type __n, const hasher& __hf) : _Base(__n, __hf) { } 86132720Skan 87132720Skan hash_set(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 template<typename _InputIterator> 92132720Skan hash_set(_InputIterator __f, _InputIterator __l) 93132720Skan : _Base(__gnu_debug::__check_valid_range(__f, __l), __l) { } 94132720Skan 95132720Skan template<typename _InputIterator> 96132720Skan hash_set(_InputIterator __f, _InputIterator __l, size_type __n) 97132720Skan : _Base(__gnu_debug::__check_valid_range(__f, __l), __l, __n) { } 98132720Skan 99132720Skan template<typename _InputIterator> 100132720Skan hash_set(_InputIterator __f, _InputIterator __l, size_type __n, 101132720Skan const hasher& __hf) 102132720Skan : _Base(__gnu_debug::__check_valid_range(__f, __l), __l, __n, __hf) { } 103132720Skan 104132720Skan template<typename _InputIterator> 105132720Skan hash_set(_InputIterator __f, _InputIterator __l, size_type __n, 106132720Skan const hasher& __hf, const key_equal& __eql, 107132720Skan const allocator_type& __a = allocator_type()) 108132720Skan : _Base(__gnu_debug::__check_valid_range(__f, __l), __l, __n, __hf, 109132720Skan __eql, __a) { } 110132720Skan 111132720Skan hash_set(const _Base& __x) : _Base(__x), _Safe_base() { } 112132720Skan 113132720Skan using _Base::size; 114132720Skan using _Base::max_size; 115132720Skan using _Base::empty; 116132720Skan 117132720Skan void 118132720Skan swap(hash_set& __x) 119132720Skan { 120132720Skan _Base::swap(__x); 121132720Skan this->_M_swap(__x); 122132720Skan } 123132720Skan 124132720Skan iterator 125132720Skan begin() const { return iterator(_Base::begin(), this); } 126132720Skan 127132720Skan iterator 128132720Skan end() const { return iterator(_Base::end(), this); } 129132720Skan 130132720Skan std::pair<iterator, bool> 131132720Skan insert(const value_type& __obj) 132132720Skan { 133132720Skan std::pair<typename _Base::iterator, bool> __res = 134132720Skan _Base::insert(__obj); 135132720Skan return std::make_pair(iterator(__res.first, this), __res.second); 136132720Skan } 137132720Skan 138169691Skan void 139169691Skan insert(const value_type* __first, const value_type* __last) 140169691Skan { 141169691Skan __glibcxx_check_valid_range(__first, __last); 142169691Skan _Base::insert(__first, __last); 143169691Skan } 144169691Skan 145169691Skan template<typename _InputIterator> 146132720Skan void 147132720Skan insert(_InputIterator __first, _InputIterator __last) 148132720Skan { 149132720Skan __glibcxx_check_valid_range(__first, __last); 150132720Skan _Base::insert(__first.base(), __last.base()); 151132720Skan } 152132720Skan 153132720Skan 154132720Skan std::pair<iterator, bool> 155132720Skan insert_noresize(const value_type& __obj) 156132720Skan { 157132720Skan std::pair<typename _Base::iterator, bool> __res = 158132720Skan _Base::insert_noresize(__obj); 159132720Skan return std::make_pair(iterator(__res.first, this), __res.second); 160132720Skan } 161132720Skan 162132720Skan iterator 163132720Skan find(const key_type& __key) const 164132720Skan { return iterator(_Base::find(__key), this); } 165132720Skan 166132720Skan using _Base::count; 167132720Skan 168132720Skan std::pair<iterator, iterator> 169132720Skan equal_range(const key_type& __key) const 170132720Skan { 171132720Skan typedef typename _Base::iterator _Base_iterator; 172132720Skan std::pair<_Base_iterator, _Base_iterator> __res = 173132720Skan _Base::equal_range(__key); 174132720Skan return std::make_pair(iterator(__res.first, this), 175132720Skan iterator(__res.second, this)); 176132720Skan } 177132720Skan 178132720Skan size_type 179132720Skan erase(const key_type& __key) 180132720Skan { 181132720Skan iterator __victim(_Base::find(__key), this); 182132720Skan if (__victim != end()) 183132720Skan return this->erase(__victim), 1; 184132720Skan else 185132720Skan return 0; 186132720Skan } 187132720Skan 188132720Skan void 189132720Skan erase(iterator __it) 190132720Skan { 191132720Skan __glibcxx_check_erase(__it); 192132720Skan __it._M_invalidate(); 193132720Skan _Base::erase(__it.base()); 194132720Skan } 195132720Skan 196132720Skan void 197132720Skan erase(iterator __first, iterator __last) 198132720Skan { 199132720Skan __glibcxx_check_erase_range(__first, __last); 200132720Skan for (iterator __tmp = __first; __tmp != __last;) 201132720Skan { 202132720Skan iterator __victim = __tmp++; 203132720Skan __victim._M_invalidate(); 204132720Skan } 205132720Skan _Base::erase(__first.base(), __last.base()); 206132720Skan } 207132720Skan 208132720Skan void 209132720Skan clear() 210132720Skan { 211132720Skan _Base::clear(); 212132720Skan this->_M_invalidate_all(); 213132720Skan } 214132720Skan 215132720Skan using _Base::resize; 216132720Skan using _Base::bucket_count; 217132720Skan using _Base::max_bucket_count; 218132720Skan using _Base::elems_in_bucket; 219132720Skan 220132720Skan _Base& 221132720Skan _M_base() { return *this; } 222132720Skan 223132720Skan const _Base& 224132720Skan _M_base() const { return *this; } 225132720Skan 226132720Skan private: 227132720Skan void 228132720Skan _M_invalidate_all() 229132720Skan { 230132720Skan typedef typename _Base::const_iterator _Base_const_iterator; 231132720Skan typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal; 232132720Skan this->_M_invalidate_if(_Not_equal(_M_base().end())); 233132720Skan } 234132720Skan }; 235132720Skan 236132720Skan template<typename _Value, typename _HashFcn, typename _EqualKey, 237132720Skan typename _Alloc> 238132720Skan inline bool 239132720Skan operator==(const hash_set<_Value, _HashFcn, _EqualKey, _Alloc>& __x, 240132720Skan const hash_set<_Value, _HashFcn, _EqualKey, _Alloc>& __y) 241132720Skan { return __x._M_base() == __y._M_base(); } 242132720Skan 243132720Skan template<typename _Value, typename _HashFcn, typename _EqualKey, 244132720Skan typename _Alloc> 245132720Skan inline bool 246132720Skan operator!=(const hash_set<_Value, _HashFcn, _EqualKey, _Alloc>& __x, 247132720Skan const hash_set<_Value, _HashFcn, _EqualKey, _Alloc>& __y) 248132720Skan { return __x._M_base() != __y._M_base(); } 249132720Skan 250132720Skan template<typename _Value, typename _HashFcn, typename _EqualKey, 251132720Skan typename _Alloc> 252132720Skan inline void 253132720Skan swap(hash_set<_Value, _HashFcn, _EqualKey, _Alloc>& __x, 254132720Skan hash_set<_Value, _HashFcn, _EqualKey, _Alloc>& __y) 255132720Skan { __x.swap(__y); } 256169691Skan} // namespace __debug 257169691Skan} // namespace __gnu_cxx 258132720Skan 259132720Skan#endif 260