1169691Skan// -*- C++ -*- 2169691Skan 3169691Skan// Copyright (C) 2005, 2006 Free Software Foundation, Inc. 4169691Skan// 5169691Skan// This file is part of the GNU ISO C++ Library. This library is free 6169691Skan// software; you can redistribute it and/or modify it under the terms 7169691Skan// of the GNU General Public License as published by the Free Software 8169691Skan// Foundation; either version 2, or (at your option) any later 9169691Skan// version. 10169691Skan 11169691Skan// This library is distributed in the hope that it will be useful, but 12169691Skan// WITHOUT ANY WARRANTY; without even the implied warranty of 13169691Skan// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14169691Skan// General Public License for more details. 15169691Skan 16169691Skan// You should have received a copy of the GNU General Public License 17169691Skan// along with this library; see the file COPYING. If not, write to 18169691Skan// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, 19169691Skan// MA 02111-1307, USA. 20169691Skan 21169691Skan// As a special exception, you may use this file as part of a free 22169691Skan// software library without restriction. Specifically, if other files 23169691Skan// instantiate templates or use macros or inline functions from this 24169691Skan// file, or you compile this file and link it with other files to 25169691Skan// produce an executable, this file does not by itself cause the 26169691Skan// resulting executable to be covered by the GNU General Public 27169691Skan// License. This exception does not however invalidate any other 28169691Skan// reasons why the executable file might be covered by the GNU General 29169691Skan// Public License. 30169691Skan 31169691Skan// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. 32169691Skan 33169691Skan// Permission to use, copy, modify, sell, and distribute this software 34169691Skan// is hereby granted without fee, provided that the above copyright 35169691Skan// notice appears in all copies, and that both that copyright notice 36169691Skan// and this permission notice appear in supporting documentation. None 37169691Skan// of the above authors, nor IBM Haifa Research Laboratories, make any 38169691Skan// representation about the suitability of this software for any 39169691Skan// purpose. It is provided "as is" without express or implied 40169691Skan// warranty. 41169691Skan 42169691Skan/** 43169691Skan * @file constructor_destructor_fn_imps.hpp 44169691Skan * Contains implementations of gp_ht_map_'s constructors, destructor, 45169691Skan * and related functions. 46169691Skan */ 47169691Skan 48169691SkanPB_DS_CLASS_T_DEC 49169691Skantypename PB_DS_CLASS_C_DEC::entry_allocator 50169691SkanPB_DS_CLASS_C_DEC::s_entry_allocator; 51169691Skan 52169691SkanPB_DS_CLASS_T_DEC 53169691Skantemplate<typename It> 54169691Skanvoid 55169691SkanPB_DS_CLASS_C_DEC:: 56169691Skancopy_from_range(It first_it, It last_it) 57169691Skan{ 58169691Skan while (first_it != last_it) 59169691Skan insert(*(first_it++)); 60169691Skan} 61169691Skan 62169691SkanPB_DS_CLASS_T_DEC 63169691SkanPB_DS_CLASS_C_DEC:: 64169691SkanPB_DS_CLASS_NAME() 65169691Skan: ranged_probe_fn_base(resize_base::get_nearest_larger_size(1)), 66169691Skan m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 67169691Skan m_entries(s_entry_allocator.allocate(m_num_e)) 68169691Skan{ 69169691Skan initialize(); 70169691Skan _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) 71169691Skan} 72169691Skan 73169691SkanPB_DS_CLASS_T_DEC 74169691SkanPB_DS_CLASS_C_DEC:: 75169691SkanPB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn) 76169691Skan: ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn), 77169691Skan m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 78169691Skan m_entries(s_entry_allocator.allocate(m_num_e)) 79169691Skan{ 80169691Skan initialize(); 81169691Skan _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) 82169691Skan} 83169691Skan 84169691SkanPB_DS_CLASS_T_DEC 85169691SkanPB_DS_CLASS_C_DEC:: 86169691SkanPB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn) 87169691Skan: hash_eq_fn_base(r_eq_fn), 88169691Skan ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn), 89169691Skan m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 90169691Skan m_entries(s_entry_allocator.allocate(m_num_e)) 91169691Skan{ 92169691Skan initialize(); 93169691Skan _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) 94169691Skan} 95169691Skan 96169691SkanPB_DS_CLASS_T_DEC 97169691SkanPB_DS_CLASS_C_DEC:: 98169691SkanPB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, 99169691Skan const Comb_Probe_Fn& r_comb_hash_fn) 100169691Skan: hash_eq_fn_base(r_eq_fn), 101169691Skan ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), 102169691Skan r_hash_fn, r_comb_hash_fn), 103169691Skan m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 104169691Skan m_entries(s_entry_allocator.allocate(m_num_e)) 105169691Skan{ 106169691Skan initialize(); 107169691Skan _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) 108169691Skan} 109169691Skan 110169691SkanPB_DS_CLASS_T_DEC 111169691SkanPB_DS_CLASS_C_DEC:: 112169691SkanPB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, 113169691Skan const Comb_Probe_Fn& comb_hash_fn, const Probe_Fn& prober) 114169691Skan: hash_eq_fn_base(r_eq_fn), 115169691Skan ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), 116169691Skan r_hash_fn, comb_hash_fn, prober), 117169691Skan m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 118169691Skan m_entries(s_entry_allocator.allocate(m_num_e)) 119169691Skan{ 120169691Skan initialize(); 121169691Skan _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) 122169691Skan} 123169691Skan 124169691SkanPB_DS_CLASS_T_DEC 125169691SkanPB_DS_CLASS_C_DEC:: 126169691SkanPB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, 127169691Skan const Comb_Probe_Fn& comb_hash_fn, const Probe_Fn& prober, 128169691Skan const Resize_Policy& r_resize_policy) 129169691Skan: hash_eq_fn_base(r_eq_fn), resize_base(r_resize_policy), 130169691Skan ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), 131169691Skan r_hash_fn, comb_hash_fn, prober), 132169691Skan m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 133169691Skan m_entries(s_entry_allocator.allocate(m_num_e)) 134169691Skan{ 135169691Skan initialize(); 136169691Skan _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) 137169691Skan} 138169691Skan 139169691SkanPB_DS_CLASS_T_DEC 140169691SkanPB_DS_CLASS_C_DEC:: 141169691SkanPB_DS_CLASS_NAME(const PB_DS_CLASS_C_DEC& other) : 142169691Skan#ifdef _GLIBCXX_DEBUG 143169691Skan map_debug_base(other), 144169691Skan#endif 145169691Skan hash_eq_fn_base(other), 146169691Skan resize_base(other), 147169691Skan ranged_probe_fn_base(other), 148169691Skan m_num_e(other.m_num_e), 149169691Skan m_num_used_e(other.m_num_used_e), 150169691Skan m_entries(s_entry_allocator.allocate(m_num_e)) 151169691Skan{ 152169691Skan for (size_type i = 0; i < m_num_e; ++i) 153169691Skan m_entries[i].m_stat = (entry_status)empty_entry_status; 154169691Skan 155169691Skan try 156169691Skan { 157169691Skan for (size_type i = 0; i < m_num_e; ++i) 158169691Skan { 159169691Skan m_entries[i].m_stat = other.m_entries[i].m_stat; 160169691Skan if (m_entries[i].m_stat == valid_entry_status) 161169691Skan new (m_entries + i) entry(other.m_entries[i]); 162169691Skan } 163169691Skan } 164169691Skan catch(...) 165169691Skan { 166169691Skan deallocate_all(); 167169691Skan __throw_exception_again; 168169691Skan } 169169691Skan _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) 170169691Skan} 171169691Skan 172169691SkanPB_DS_CLASS_T_DEC 173169691SkanPB_DS_CLASS_C_DEC:: 174169691Skan~PB_DS_CLASS_NAME() 175169691Skan{ deallocate_all(); } 176169691Skan 177169691SkanPB_DS_CLASS_T_DEC 178169691Skanvoid 179169691SkanPB_DS_CLASS_C_DEC:: 180169691Skanswap(PB_DS_CLASS_C_DEC& other) 181169691Skan{ 182169691Skan _GLIBCXX_DEBUG_ONLY(assert_valid()); 183169691Skan _GLIBCXX_DEBUG_ONLY(other.assert_valid()); 184169691Skan std::swap(m_num_e, other.m_num_e); 185169691Skan std::swap(m_num_used_e, other.m_num_used_e); 186169691Skan std::swap(m_entries, other.m_entries); 187169691Skan ranged_probe_fn_base::swap(other); 188169691Skan hash_eq_fn_base::swap(other); 189169691Skan resize_base::swap(other); 190169691Skan _GLIBCXX_DEBUG_ONLY(map_debug_base::swap(other)); 191169691Skan _GLIBCXX_DEBUG_ONLY(assert_valid()); 192169691Skan _GLIBCXX_DEBUG_ONLY(other.assert_valid()); 193169691Skan} 194169691Skan 195169691SkanPB_DS_CLASS_T_DEC 196169691Skanvoid 197169691SkanPB_DS_CLASS_C_DEC:: 198169691Skandeallocate_all() 199169691Skan{ 200169691Skan clear(); 201169691Skan erase_all_valid_entries(m_entries, m_num_e); 202169691Skan s_entry_allocator.deallocate(m_entries, m_num_e); 203169691Skan} 204169691Skan 205169691SkanPB_DS_CLASS_T_DEC 206169691Skanvoid 207169691SkanPB_DS_CLASS_C_DEC:: 208169691Skanerase_all_valid_entries(entry_array a_entries_resized, size_type len) 209169691Skan{ 210169691Skan for (size_type pos = 0; pos < len; ++pos) 211169691Skan { 212169691Skan entry_pointer p_e = &a_entries_resized[pos]; 213169691Skan if (p_e->m_stat == valid_entry_status) 214169691Skan p_e->m_value.~value_type(); 215169691Skan } 216169691Skan} 217169691Skan 218169691SkanPB_DS_CLASS_T_DEC 219169691Skanvoid 220169691SkanPB_DS_CLASS_C_DEC:: 221169691Skaninitialize() 222169691Skan{ 223169691Skan Resize_Policy::notify_resized(m_num_e); 224169691Skan Resize_Policy::notify_cleared(); 225169691Skan ranged_probe_fn_base::notify_resized(m_num_e); 226169691Skan for (size_type i = 0; i < m_num_e; ++i) 227169691Skan m_entries[i].m_stat = empty_entry_status; 228169691Skan} 229169691Skan 230