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 cc_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 53169691Skantypename PB_DS_CLASS_C_DEC::entry_pointer_allocator 54169691SkanPB_DS_CLASS_C_DEC::s_entry_pointer_allocator; 55169691Skan 56169691SkanPB_DS_CLASS_T_DEC 57169691Skantemplate<typename It> 58169691Skanvoid 59169691SkanPB_DS_CLASS_C_DEC:: 60169691Skancopy_from_range(It first_it, It last_it) 61169691Skan{ 62169691Skan while (first_it != last_it) 63169691Skan insert(*(first_it++)); 64169691Skan} 65169691Skan 66169691SkanPB_DS_CLASS_T_DEC 67169691SkanPB_DS_CLASS_C_DEC:: 68169691SkanPB_DS_CLASS_NAME() : 69169691Skan ranged_hash_fn_base(resize_base::get_nearest_larger_size(1)), 70169691Skan m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 71169691Skan m_entries(s_entry_pointer_allocator.allocate(m_num_e)) 72169691Skan{ 73169691Skan initialize(); 74169691Skan _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) 75169691Skan} 76169691Skan 77169691SkanPB_DS_CLASS_T_DEC 78169691SkanPB_DS_CLASS_C_DEC:: 79169691SkanPB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn) : 80169691Skan ranged_hash_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn), 81169691Skan m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 82169691Skan m_entries(s_entry_pointer_allocator.allocate(m_num_e)) 83169691Skan{ 84169691Skan initialize(); 85169691Skan _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) 86169691Skan} 87169691Skan 88169691SkanPB_DS_CLASS_T_DEC 89169691SkanPB_DS_CLASS_C_DEC:: 90169691SkanPB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn) : 91169691Skan PB_DS_HASH_EQ_FN_C_DEC(r_eq_fn), 92169691Skan ranged_hash_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn), 93169691Skan m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 94169691Skan m_entries(s_entry_pointer_allocator.allocate(m_num_e)) 95169691Skan{ 96169691Skan std::fill(m_entries, m_entries + m_num_e, (entry_pointer)NULL); 97169691Skan Resize_Policy::notify_cleared(); 98169691Skan ranged_hash_fn_base::notify_resized(m_num_e); 99169691Skan _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) 100169691Skan} 101169691Skan 102169691SkanPB_DS_CLASS_T_DEC 103169691SkanPB_DS_CLASS_C_DEC:: 104169691SkanPB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, const Comb_Hash_Fn& r_comb_hash_fn) : 105169691Skan PB_DS_HASH_EQ_FN_C_DEC(r_eq_fn), 106169691Skan ranged_hash_fn_base(resize_base::get_nearest_larger_size(1), 107169691Skan r_hash_fn, r_comb_hash_fn), 108169691Skan m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 109169691Skan m_entries(s_entry_pointer_allocator.allocate(m_num_e)) 110169691Skan{ 111169691Skan initialize(); 112169691Skan _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) 113169691Skan} 114169691Skan 115169691SkanPB_DS_CLASS_T_DEC 116169691SkanPB_DS_CLASS_C_DEC:: 117169691SkanPB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, const Comb_Hash_Fn& r_comb_hash_fn, const Resize_Policy& r_resize_policy) : 118169691Skan PB_DS_HASH_EQ_FN_C_DEC(r_eq_fn), 119169691Skan Resize_Policy(r_resize_policy), 120169691Skan ranged_hash_fn_base(resize_base::get_nearest_larger_size(1), 121169691Skan r_hash_fn, r_comb_hash_fn), 122169691Skan m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 123169691Skan m_entries(s_entry_pointer_allocator.allocate(m_num_e)) 124169691Skan{ 125169691Skan initialize(); 126169691Skan _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) 127169691Skan} 128169691Skan 129169691SkanPB_DS_CLASS_T_DEC 130169691SkanPB_DS_CLASS_C_DEC:: 131169691SkanPB_DS_CLASS_NAME(const PB_DS_CLASS_C_DEC& other) : 132169691Skan#ifdef _GLIBCXX_DEBUG 133169691Skan map_debug_base(other), 134169691Skan#endif 135169691Skan PB_DS_HASH_EQ_FN_C_DEC(other), 136169691Skan resize_base(other), ranged_hash_fn_base(other), 137169691Skan m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 138169691Skan m_entries(m_entries = s_entry_pointer_allocator.allocate(m_num_e)) 139169691Skan{ 140169691Skan initialize(); 141169691Skan _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) 142169691Skan try 143169691Skan { 144169691Skan copy_from_range(other.begin(), other.end()); 145169691Skan } 146169691Skan catch(...) 147169691Skan { 148169691Skan deallocate_all(); 149169691Skan __throw_exception_again; 150169691Skan } 151169691Skan _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) 152169691Skan} 153169691Skan 154169691SkanPB_DS_CLASS_T_DEC 155169691SkanPB_DS_CLASS_C_DEC:: 156169691Skan~PB_DS_CLASS_NAME() 157169691Skan{ deallocate_all(); } 158169691Skan 159169691SkanPB_DS_CLASS_T_DEC 160169691Skanvoid 161169691SkanPB_DS_CLASS_C_DEC:: 162169691Skanswap(PB_DS_CLASS_C_DEC& other) 163169691Skan{ 164169691Skan _GLIBCXX_DEBUG_ONLY(assert_valid()); 165169691Skan _GLIBCXX_DEBUG_ONLY(other.assert_valid()); 166169691Skan 167169691Skan std::swap(m_entries, other.m_entries); 168169691Skan std::swap(m_num_e, other.m_num_e); 169169691Skan std::swap(m_num_used_e, other.m_num_used_e); 170169691Skan ranged_hash_fn_base::swap(other); 171169691Skan hash_eq_fn_base::swap(other); 172169691Skan resize_base::swap(other); 173169691Skan 174169691Skan _GLIBCXX_DEBUG_ONLY(map_debug_base::swap(other)); 175169691Skan _GLIBCXX_DEBUG_ONLY(assert_valid()); 176169691Skan _GLIBCXX_DEBUG_ONLY(other.assert_valid()); 177169691Skan} 178169691Skan 179169691SkanPB_DS_CLASS_T_DEC 180169691Skanvoid 181169691SkanPB_DS_CLASS_C_DEC:: 182169691Skandeallocate_all() 183169691Skan{ 184169691Skan clear(); 185169691Skan s_entry_pointer_allocator.deallocate(m_entries, m_num_e); 186169691Skan} 187169691Skan 188169691SkanPB_DS_CLASS_T_DEC 189169691Skanvoid 190169691SkanPB_DS_CLASS_C_DEC:: 191169691Skaninitialize() 192169691Skan{ 193169691Skan std::fill(m_entries, m_entries + m_num_e, entry_pointer(NULL)); 194169691Skan Resize_Policy::notify_resized(m_num_e); 195169691Skan Resize_Policy::notify_cleared(); 196169691Skan ranged_hash_fn_base::notify_resized(m_num_e); 197169691Skan} 198