constructor_destructor_fn_imps.hpp revision 169691
1191783Srmacklem// -*- C++ -*- 2191783Srmacklem 3191783Srmacklem// Copyright (C) 2005, 2006 Free Software Foundation, Inc. 4191783Srmacklem// 5191783Srmacklem// This file is part of the GNU ISO C++ Library. This library is free 6191783Srmacklem// software; you can redistribute it and/or modify it under the terms 7191783Srmacklem// of the GNU General Public License as published by the Free Software 8191783Srmacklem// Foundation; either version 2, or (at your option) any later 9191783Srmacklem// version. 10191783Srmacklem 11191783Srmacklem// This library is distributed in the hope that it will be useful, but 12191783Srmacklem// WITHOUT ANY WARRANTY; without even the implied warranty of 13191783Srmacklem// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14191783Srmacklem// General Public License for more details. 15191783Srmacklem 16191783Srmacklem// You should have received a copy of the GNU General Public License 17191783Srmacklem// along with this library; see the file COPYING. If not, write to 18191783Srmacklem// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, 19191783Srmacklem// MA 02111-1307, USA. 20191783Srmacklem 21191783Srmacklem// As a special exception, you may use this file as part of a free 22191783Srmacklem// software library without restriction. Specifically, if other files 23191783Srmacklem// instantiate templates or use macros or inline functions from this 24191783Srmacklem// file, or you compile this file and link it with other files to 25191783Srmacklem// produce an executable, this file does not by itself cause the 26191783Srmacklem// resulting executable to be covered by the GNU General Public 27191783Srmacklem// License. This exception does not however invalidate any other 28191783Srmacklem// reasons why the executable file might be covered by the GNU General 29191783Srmacklem// Public License. 30191783Srmacklem 31191783Srmacklem// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. 32191783Srmacklem 33191783Srmacklem// Permission to use, copy, modify, sell, and distribute this software 34191783Srmacklem// is hereby granted without fee, provided that the above copyright 35191783Srmacklem// notice appears in all copies, and that both that copyright notice 36191783Srmacklem// and this permission notice appear in supporting documentation. None 37224778Srwatson// of the above authors, nor IBM Haifa Research Laboratories, make any 38224778Srwatson// representation about the suitability of this software for any 39191783Srmacklem// purpose. It is provided "as is" without express or implied 40191783Srmacklem// warranty. 41191783Srmacklem 42191783Srmacklem/** 43191783Srmacklem * @file constructor_destructor_fn_imps.hpp 44191783Srmacklem * Contains implementations of cc_ht_map_'s constructors, destructor, 45191783Srmacklem * and related functions. 46214255Srmacklem */ 47191783Srmacklem 48192503SrmacklemPB_DS_CLASS_T_DEC 49192503Srmacklemtypename PB_DS_CLASS_C_DEC::entry_allocator 50191783SrmacklemPB_DS_CLASS_C_DEC::s_entry_allocator; 51219028Snetchild 52219028SnetchildPB_DS_CLASS_T_DEC 53191783Srmacklemtypename PB_DS_CLASS_C_DEC::entry_pointer_allocator 54191783SrmacklemPB_DS_CLASS_C_DEC::s_entry_pointer_allocator; 55191783Srmacklem 56191783SrmacklemPB_DS_CLASS_T_DEC 57191783Srmacklemtemplate<typename It> 58191783Srmacklemvoid 59220530SrmacklemPB_DS_CLASS_C_DEC:: 60243738Srmacklemcopy_from_range(It first_it, It last_it) 61191783Srmacklem{ 62191783Srmacklem while (first_it != last_it) 63255532Srmacklem insert(*(first_it++)); 64255532Srmacklem} 65191783Srmacklem 66191783SrmacklemPB_DS_CLASS_T_DEC 67191783SrmacklemPB_DS_CLASS_C_DEC:: 68217432SrmacklemPB_DS_CLASS_NAME() : 69217432Srmacklem ranged_hash_fn_base(resize_base::get_nearest_larger_size(1)), 70217432Srmacklem m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 71217432Srmacklem m_entries(s_entry_pointer_allocator.allocate(m_num_e)) 72192503Srmacklem{ 73191783Srmacklem initialize(); 74192255Srmacklem _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) 75192255Srmacklem} 76191783Srmacklem 77220645SrmacklemPB_DS_CLASS_T_DEC 78191783SrmacklemPB_DS_CLASS_C_DEC:: 79191783SrmacklemPB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn) : 80191783Srmacklem ranged_hash_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn), 81192255Srmacklem m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 82192255Srmacklem m_entries(s_entry_pointer_allocator.allocate(m_num_e)) 83221615Srmacklem{ 84221615Srmacklem initialize(); 85220645Srmacklem _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) 86221615Srmacklem} 87192255Srmacklem 88221615SrmacklemPB_DS_CLASS_T_DEC 89192255SrmacklemPB_DS_CLASS_C_DEC:: 90221615SrmacklemPB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn) : 91192255Srmacklem PB_DS_HASH_EQ_FN_C_DEC(r_eq_fn), 92221615Srmacklem ranged_hash_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn), 93192255Srmacklem m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 94191783Srmacklem m_entries(s_entry_pointer_allocator.allocate(m_num_e)) 95229617Sjhb{ 96229617Sjhb std::fill(m_entries, m_entries + m_num_e, (entry_pointer)NULL); 97191783Srmacklem Resize_Policy::notify_cleared(); 98191783Srmacklem ranged_hash_fn_base::notify_resized(m_num_e); 99191783Srmacklem _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) 100191783Srmacklem} 101191783Srmacklem 102191783SrmacklemPB_DS_CLASS_T_DEC 103229617SjhbPB_DS_CLASS_C_DEC:: 104191783SrmacklemPB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, const Comb_Hash_Fn& r_comb_hash_fn) : 105191783Srmacklem PB_DS_HASH_EQ_FN_C_DEC(r_eq_fn), 106191783Srmacklem ranged_hash_fn_base(resize_base::get_nearest_larger_size(1), 107191783Srmacklem r_hash_fn, r_comb_hash_fn), 108191783Srmacklem m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 109191783Srmacklem m_entries(s_entry_pointer_allocator.allocate(m_num_e)) 110229617Sjhb{ 111229617Sjhb initialize(); 112229617Sjhb _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) 113229617Sjhb} 114229617Sjhb 115229617SjhbPB_DS_CLASS_T_DEC 116229617SjhbPB_DS_CLASS_C_DEC:: 117229617SjhbPB_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) : 118229617Sjhb PB_DS_HASH_EQ_FN_C_DEC(r_eq_fn), 119229617Sjhb Resize_Policy(r_resize_policy), 120229617Sjhb ranged_hash_fn_base(resize_base::get_nearest_larger_size(1), 121229617Sjhb r_hash_fn, r_comb_hash_fn), 122229617Sjhb m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 123229617Sjhb m_entries(s_entry_pointer_allocator.allocate(m_num_e)) 124229617Sjhb{ 125229617Sjhb initialize(); 126229617Sjhb _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) 127229617Sjhb} 128229617Sjhb 129229617SjhbPB_DS_CLASS_T_DEC 130229617SjhbPB_DS_CLASS_C_DEC:: 131229617SjhbPB_DS_CLASS_NAME(const PB_DS_CLASS_C_DEC& other) : 132229617Sjhb#ifdef _GLIBCXX_DEBUG 133229617Sjhb map_debug_base(other), 134229617Sjhb#endif 135229617Sjhb PB_DS_HASH_EQ_FN_C_DEC(other), 136229617Sjhb resize_base(other), ranged_hash_fn_base(other), 137229617Sjhb m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), 138229617Sjhb m_entries(m_entries = s_entry_pointer_allocator.allocate(m_num_e)) 139229617Sjhb{ 140229617Sjhb initialize(); 141229617Sjhb _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) 142229617Sjhb try 143229617Sjhb { 144229617Sjhb copy_from_range(other.begin(), other.end()); 145229617Sjhb } 146229617Sjhb catch(...) 147229617Sjhb { 148229617Sjhb deallocate_all(); 149229617Sjhb __throw_exception_again; 150229617Sjhb } 151229617Sjhb _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) 152229617Sjhb} 153229617Sjhb 154229617SjhbPB_DS_CLASS_T_DEC 155229617SjhbPB_DS_CLASS_C_DEC:: 156229617Sjhb~PB_DS_CLASS_NAME() 157229617Sjhb{ deallocate_all(); } 158229617Sjhb 159229617SjhbPB_DS_CLASS_T_DEC 160229617Sjhbvoid 161229617SjhbPB_DS_CLASS_C_DEC:: 162229617Sjhbswap(PB_DS_CLASS_C_DEC& other) 163229617Sjhb{ 164229617Sjhb _GLIBCXX_DEBUG_ONLY(assert_valid()); 165229617Sjhb _GLIBCXX_DEBUG_ONLY(other.assert_valid()); 166229617Sjhb 167191783Srmacklem std::swap(m_entries, other.m_entries); 168191783Srmacklem std::swap(m_num_e, other.m_num_e); 169191783Srmacklem std::swap(m_num_used_e, other.m_num_used_e); 170191783Srmacklem ranged_hash_fn_base::swap(other); 171216693Srmacklem hash_eq_fn_base::swap(other); 172191783Srmacklem resize_base::swap(other); 173191783Srmacklem 174191783Srmacklem _GLIBCXX_DEBUG_ONLY(map_debug_base::swap(other)); 175216693Srmacklem _GLIBCXX_DEBUG_ONLY(assert_valid()); 176216693Srmacklem _GLIBCXX_DEBUG_ONLY(other.assert_valid()); 177216693Srmacklem} 178216693Srmacklem 179216693SrmacklemPB_DS_CLASS_T_DEC 180216693Srmacklemvoid 181224083SzackPB_DS_CLASS_C_DEC:: 182216693Srmacklemdeallocate_all() 183224081Szack{ 184216693Srmacklem clear(); 185191783Srmacklem s_entry_pointer_allocator.deallocate(m_entries, m_num_e); 186191783Srmacklem} 187216693Srmacklem 188224082SzackPB_DS_CLASS_T_DEC 189224086Szackvoid 190224086SzackPB_DS_CLASS_C_DEC:: 191191783Srmackleminitialize() 192191783Srmacklem{ 193191783Srmacklem std::fill(m_entries, m_entries + m_num_e, entry_pointer(NULL)); 194191783Srmacklem Resize_Policy::notify_resized(m_num_e); 195191783Srmacklem Resize_Policy::notify_cleared(); 196191783Srmacklem ranged_hash_fn_base::notify_resized(m_num_e); 197191783Srmacklem} 198191783Srmacklem