libstdc++
cc_hash_table_map_/constructor_destructor_fn_imps.hpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011
00004 // Free Software Foundation, Inc.
00005 //
00006 // This file is part of the GNU ISO C++ Library.  This library is free
00007 // software; you can redistribute it and/or modify it under the terms
00008 // of the GNU General Public License as published by the Free Software
00009 // Foundation; either version 3, or (at your option) any later
00010 // version.
00011 
00012 // This library is distributed in the hope that it will be useful, but
00013 // WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 // General Public License for more details.
00016 
00017 // Under Section 7 of GPL version 3, you are granted additional
00018 // permissions described in the GCC Runtime Library Exception, version
00019 // 3.1, as published by the Free Software Foundation.
00020 
00021 // You should have received a copy of the GNU General Public License and
00022 // a copy of the GCC Runtime Library Exception along with this program;
00023 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00024 // <http://www.gnu.org/licenses/>.
00025 
00026 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
00027 
00028 // Permission to use, copy, modify, sell, and distribute this software
00029 // is hereby granted without fee, provided that the above copyright
00030 // notice appears in all copies, and that both that copyright notice
00031 // and this permission notice appear in supporting documentation. None
00032 // of the above authors, nor IBM Haifa Research Laboratories, make any
00033 // representation about the suitability of this software for any
00034 // purpose. It is provided "as is" without express or implied
00035 // warranty.
00036 
00037 /**
00038  * @file cc_hash_table_map_/constructor_destructor_fn_imps.hpp
00039  * Contains implementations of cc_ht_map_'s constructors, destructor,
00040  * and related functions.
00041  */
00042 
00043 PB_DS_CLASS_T_DEC
00044 typename PB_DS_CLASS_C_DEC::entry_allocator
00045 PB_DS_CLASS_C_DEC::s_entry_allocator;
00046 
00047 PB_DS_CLASS_T_DEC
00048 typename PB_DS_CLASS_C_DEC::entry_pointer_allocator
00049 PB_DS_CLASS_C_DEC::s_entry_pointer_allocator;
00050 
00051 PB_DS_CLASS_T_DEC
00052 template<typename It>
00053 void
00054 PB_DS_CLASS_C_DEC::
00055 copy_from_range(It first_it, It last_it)
00056 {
00057   while (first_it != last_it)
00058     insert(*(first_it++));
00059 }
00060 
00061 PB_DS_CLASS_T_DEC
00062 PB_DS_CLASS_C_DEC::
00063 PB_DS_CC_HASH_NAME() :
00064   ranged_hash_fn_base(resize_base::get_nearest_larger_size(1)),
00065   m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0),
00066   m_entries(s_entry_pointer_allocator.allocate(m_num_e))
00067 {
00068   initialize();
00069   PB_DS_ASSERT_VALID((*this))
00070 }
00071 
00072 PB_DS_CLASS_T_DEC
00073 PB_DS_CLASS_C_DEC::
00074 PB_DS_CC_HASH_NAME(const Hash_Fn& r_hash_fn) :
00075   ranged_hash_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn),
00076   m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0),
00077   m_entries(s_entry_pointer_allocator.allocate(m_num_e))
00078 {
00079   initialize();
00080   PB_DS_ASSERT_VALID((*this))
00081 }
00082 
00083 PB_DS_CLASS_T_DEC
00084 PB_DS_CLASS_C_DEC::
00085 PB_DS_CC_HASH_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn) :
00086   PB_DS_HASH_EQ_FN_C_DEC(r_eq_fn),
00087   ranged_hash_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn),
00088   m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0),
00089   m_entries(s_entry_pointer_allocator.allocate(m_num_e))
00090 {
00091   std::fill(m_entries, m_entries + m_num_e, (entry_pointer)0);
00092   Resize_Policy::notify_cleared();
00093   ranged_hash_fn_base::notify_resized(m_num_e);
00094   PB_DS_ASSERT_VALID((*this))
00095 }
00096 
00097 PB_DS_CLASS_T_DEC
00098 PB_DS_CLASS_C_DEC::
00099 PB_DS_CC_HASH_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, 
00100            const Comb_Hash_Fn& r_comb_hash_fn) :
00101   PB_DS_HASH_EQ_FN_C_DEC(r_eq_fn),
00102   ranged_hash_fn_base(resize_base::get_nearest_larger_size(1),
00103               r_hash_fn, r_comb_hash_fn),
00104   m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0),
00105   m_entries(s_entry_pointer_allocator.allocate(m_num_e))
00106 {
00107   initialize();
00108   PB_DS_ASSERT_VALID((*this))
00109 }
00110 
00111 PB_DS_CLASS_T_DEC
00112 PB_DS_CLASS_C_DEC::
00113 PB_DS_CC_HASH_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, 
00114            const Comb_Hash_Fn& r_comb_hash_fn, 
00115            const Resize_Policy& r_resize_policy) :
00116   PB_DS_HASH_EQ_FN_C_DEC(r_eq_fn),
00117   Resize_Policy(r_resize_policy),
00118   ranged_hash_fn_base(resize_base::get_nearest_larger_size(1),
00119               r_hash_fn, r_comb_hash_fn),
00120   m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0),
00121   m_entries(s_entry_pointer_allocator.allocate(m_num_e))
00122 {
00123   initialize();
00124   PB_DS_ASSERT_VALID((*this))
00125 }
00126 
00127 PB_DS_CLASS_T_DEC
00128 PB_DS_CLASS_C_DEC::
00129 PB_DS_CC_HASH_NAME(const PB_DS_CLASS_C_DEC& other) :
00130   PB_DS_HASH_EQ_FN_C_DEC(other),
00131   resize_base(other), ranged_hash_fn_base(other),
00132   m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0),
00133   m_entries(s_entry_pointer_allocator.allocate(m_num_e))
00134 {
00135   initialize();
00136   PB_DS_ASSERT_VALID((*this))
00137     __try
00138       {
00139     copy_from_range(other.begin(), other.end());
00140       }
00141     __catch(...)
00142       {
00143     deallocate_all();
00144     __throw_exception_again;
00145       }
00146   PB_DS_ASSERT_VALID((*this))
00147 }
00148 
00149 PB_DS_CLASS_T_DEC
00150 PB_DS_CLASS_C_DEC::
00151 ~PB_DS_CC_HASH_NAME()
00152 { deallocate_all(); }
00153 
00154 PB_DS_CLASS_T_DEC
00155 void
00156 PB_DS_CLASS_C_DEC::
00157 swap(PB_DS_CLASS_C_DEC& other)
00158 {
00159   PB_DS_ASSERT_VALID((*this))
00160   PB_DS_ASSERT_VALID(other)
00161 
00162   std::swap(m_entries, other.m_entries);
00163   std::swap(m_num_e, other.m_num_e);
00164   std::swap(m_num_used_e, other.m_num_used_e);
00165   ranged_hash_fn_base::swap(other);
00166   hash_eq_fn_base::swap(other);
00167   resize_base::swap(other);
00168 
00169   _GLIBCXX_DEBUG_ONLY(debug_base::swap(other));
00170   PB_DS_ASSERT_VALID((*this))
00171   PB_DS_ASSERT_VALID(other)
00172 }
00173 
00174 PB_DS_CLASS_T_DEC
00175 void
00176 PB_DS_CLASS_C_DEC::
00177 deallocate_all()
00178 {
00179   clear();
00180   s_entry_pointer_allocator.deallocate(m_entries, m_num_e);
00181 }
00182 
00183 PB_DS_CLASS_T_DEC
00184 void
00185 PB_DS_CLASS_C_DEC::
00186 initialize()
00187 {
00188   std::fill(m_entries, m_entries + m_num_e, entry_pointer(0));
00189   Resize_Policy::notify_resized(m_num_e);
00190   Resize_Policy::notify_cleared();
00191   ranged_hash_fn_base::notify_resized(m_num_e);
00192 }