libstdc++
|
00001 // -*- C++ -*- 00002 00003 // Copyright (C) 2005-2015 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the terms 00007 // of the GNU General Public License as published by the Free Software 00008 // Foundation; either version 3, or (at your option) any later 00009 // version. 00010 00011 // This library is distributed in the hope that it will be useful, but 00012 // WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 // General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. 00026 00027 // Permission to use, copy, modify, sell, and distribute this software 00028 // is hereby granted without fee, provided that the above copyright 00029 // notice appears in all copies, and that both that copyright notice 00030 // and this permission notice appear in supporting documentation. None 00031 // of the above authors, nor IBM Haifa Research Laboratories, make any 00032 // representation about the suitability of this software for any 00033 // purpose. It is provided "as is" without express or implied 00034 // warranty. 00035 00036 /** 00037 * @file cc_hash_table_map_/resize_fn_imps.hpp 00038 * Contains implementations of cc_ht_map_'s resize related functions. 00039 */ 00040 00041 PB_DS_CLASS_T_DEC 00042 inline bool 00043 PB_DS_CLASS_C_DEC:: 00044 do_resize_if_needed() 00045 { 00046 if (!resize_base::is_resize_needed()) 00047 return false; 00048 resize_imp(resize_base::get_new_size(m_num_e, m_num_used_e)); 00049 return true; 00050 } 00051 00052 PB_DS_CLASS_T_DEC 00053 void 00054 PB_DS_CLASS_C_DEC:: 00055 do_resize(size_type len) 00056 { resize_imp(resize_base::get_nearest_larger_size(len)); } 00057 00058 PB_DS_CLASS_T_DEC 00059 inline void 00060 PB_DS_CLASS_C_DEC:: 00061 do_resize_if_needed_no_throw() 00062 { 00063 if (!resize_base::is_resize_needed()) 00064 return; 00065 00066 __try 00067 { 00068 resize_imp(resize_base::get_new_size(m_num_e, m_num_used_e)); 00069 } 00070 __catch(...) 00071 { } 00072 00073 PB_DS_ASSERT_VALID((*this)) 00074 } 00075 00076 PB_DS_CLASS_T_DEC 00077 void 00078 PB_DS_CLASS_C_DEC:: 00079 resize_imp(size_type new_size) 00080 { 00081 PB_DS_ASSERT_VALID((*this)) 00082 if (new_size == m_num_e) 00083 return; 00084 00085 const size_type old_size = m_num_e; 00086 entry_pointer_array a_p_entries_resized; 00087 00088 // Following line might throw an exception. 00089 ranged_hash_fn_base::notify_resized(new_size); 00090 00091 __try 00092 { 00093 // Following line might throw an exception. 00094 a_p_entries_resized = s_entry_pointer_allocator.allocate(new_size); 00095 m_num_e = new_size; 00096 } 00097 __catch(...) 00098 { 00099 ranged_hash_fn_base::notify_resized(old_size); 00100 __throw_exception_again; 00101 } 00102 00103 // At this point no exceptions can be thrown. 00104 resize_imp_no_exceptions(new_size, a_p_entries_resized, old_size); 00105 Resize_Policy::notify_resized(new_size); 00106 PB_DS_ASSERT_VALID((*this)) 00107 } 00108 00109 PB_DS_CLASS_T_DEC 00110 void 00111 PB_DS_CLASS_C_DEC:: 00112 resize_imp_no_exceptions(size_type new_size, entry_pointer_array a_p_entries_resized, size_type old_size) 00113 { 00114 std::fill(a_p_entries_resized, a_p_entries_resized + m_num_e, 00115 entry_pointer(0)); 00116 00117 for (size_type pos = 0; pos < old_size; ++pos) 00118 { 00119 entry_pointer p_e = m_entries[pos]; 00120 while (p_e != 0) 00121 p_e = resize_imp_no_exceptions_reassign_pointer(p_e, a_p_entries_resized, traits_base::m_store_extra_indicator); 00122 } 00123 00124 m_num_e = new_size; 00125 _GLIBCXX_DEBUG_ONLY(assert_entry_pointer_array_valid(a_p_entries_resized, 00126 __FILE__, __LINE__);) 00127 s_entry_pointer_allocator.deallocate(m_entries, old_size); 00128 m_entries = a_p_entries_resized; 00129 PB_DS_ASSERT_VALID((*this)) 00130 } 00131 00132 #include <ext/pb_ds/detail/cc_hash_table_map_/resize_no_store_hash_fn_imps.hpp> 00133 #include <ext/pb_ds/detail/cc_hash_table_map_/resize_store_hash_fn_imps.hpp> 00134