1279377Simp// -*- C++ -*- 2279377Simp 3279377Simp// Copyright (C) 2005, 2006 Free Software Foundation, Inc. 4279377Simp// 5279377Simp// This file is part of the GNU ISO C++ Library. This library is free 6279377Simp// software; you can redistribute it and/or modify it under the terms 7279377Simp// of the GNU General Public License as published by the Free Software 8279377Simp// Foundation; either version 2, or (at your option) any later 9279377Simp// version. 10279377Simp 11279377Simp// This library is distributed in the hope that it will be useful, but 12279377Simp// WITHOUT ANY WARRANTY; without even the implied warranty of 13279377Simp// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14279377Simp// General Public License for more details. 15279377Simp 16279377Simp// You should have received a copy of the GNU General Public License 17279377Simp// along with this library; see the file COPYING. If not, write to 18279377Simp// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, 19279377Simp// MA 02111-1307, USA. 20279377Simp 21279377Simp// As a special exception, you may use this file as part of a free 22279377Simp// software library without restriction. Specifically, if other files 23279377Simp// instantiate templates or use macros or inline functions from this 24279377Simp// file, or you compile this file and link it with other files to 25279377Simp// produce an executable, this file does not by itself cause the 26279377Simp// resulting executable to be covered by the GNU General Public 27279377Simp// License. This exception does not however invalidate any other 28279377Simp// reasons why the executable file might be covered by the GNU General 29279377Simp// Public License. 30279377Simp 31279377Simp// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. 32279377Simp 33279377Simp// Permission to use, copy, modify, sell, and distribute this software 34279377Simp// is hereby granted without fee, provided that the above copyright 35279377Simp// notice appears in all copies, and that both that copyright notice 36279377Simp// and this permission notice appear in supporting documentation. None 37279377Simp// of the above authors, nor IBM Haifa Research Laboratories, make any 38279377Simp// representation about the suitability of this software for any 39279377Simp// purpose. It is provided "as is" without express or implied 40279377Simp// warranty. 41279377Simp 42279377Simp/** 43279377Simp * @file resize_fn_imps.hpp 44279377Simp * Contains implementations of gp_ht_map_'s resize related functions. 45279377Simp */ 46279377Simp 47279377SimpPB_DS_CLASS_T_DEC 48279377Simpinline bool 49279377SimpPB_DS_CLASS_C_DEC:: 50279377Simpdo_resize_if_needed() 51279377Simp{ 52279377Simp if (!resize_base::is_resize_needed()) 53279377Simp return false; 54279377Simp resize_imp(resize_base::get_new_size(m_num_e, m_num_used_e)); 55279377Simp return true; 56279377Simp} 57279377Simp 58279377SimpPB_DS_CLASS_T_DEC 59279377Simpvoid 60279377SimpPB_DS_CLASS_C_DEC:: 61279377Simpdo_resize(size_type n) 62279377Simp{ resize_imp(resize_base::get_nearest_larger_size(n)); } 63279377Simp 64279377SimpPB_DS_CLASS_T_DEC 65279377Simpinline void 66279377SimpPB_DS_CLASS_C_DEC:: 67279377Simpdo_resize_if_needed_no_throw() 68279377Simp{ 69279377Simp if (!resize_base::is_resize_needed()) 70279377Simp return; 71279377Simp 72279377Simp try 73279377Simp { 74279377Simp resize_imp(resize_base::get_new_size(m_num_e, m_num_used_e)); 75279377Simp } 76279377Simp catch(...) 77279377Simp { } 78279377Simp 79279377Simp _GLIBCXX_DEBUG_ONLY(assert_valid();) 80279377Simp} 81279377Simp 82279377SimpPB_DS_CLASS_T_DEC 83279377Simpvoid 84279377SimpPB_DS_CLASS_C_DEC:: 85279377Simpresize_imp(size_type new_size) 86279377Simp{ 87279377Simp#ifdef PB_DS_REGRESSION 88279377Simp typename Allocator::group_throw_prob_adjustor adjust(m_num_e); 89279377Simp#endif 90279377Simp 91279377Simp if (new_size == m_num_e) 92279377Simp return; 93279377Simp 94279377Simp _GLIBCXX_DEBUG_ONLY(assert_valid();) 95279377Simp const size_type old_size = m_num_e; 96279377Simp entry_array a_entries_resized = NULL; 97279377Simp 98279377Simp // Following line might throw an exception. 99279377Simp a_entries_resized = s_entry_allocator.allocate(new_size); 100279377Simp 101279377Simp ranged_probe_fn_base::notify_resized(new_size); 102279377Simp m_num_e = new_size; 103279377Simp 104279377Simp for (size_type i = 0; i < m_num_e; ++i) 105279377Simp a_entries_resized[i].m_stat = empty_entry_status; 106279377Simp 107279377Simp try 108279377Simp { 109279377Simp resize_imp(a_entries_resized, old_size); 110279377Simp } 111279377Simp catch(...) 112279377Simp { 113279377Simp erase_all_valid_entries(a_entries_resized, new_size); 114279377Simp m_num_e = old_size; 115279377Simp s_entry_allocator.deallocate(a_entries_resized, new_size); 116279377Simp ranged_probe_fn_base::notify_resized(old_size); 117279377Simp __throw_exception_again; 118279377Simp } 119279377Simp 120279377Simp // At this point no exceptions can be thrown. 121279377Simp _GLIBCXX_DEBUG_ONLY(assert_entry_array_valid(a_entries_resized, traits_base::m_store_extra_indicator);) 122279377Simp 123279377Simp Resize_Policy::notify_resized(new_size); 124279377Simp erase_all_valid_entries(m_entries, old_size); 125279377Simp s_entry_allocator.deallocate(m_entries, old_size); 126279377Simp m_entries = a_entries_resized; 127279377Simp _GLIBCXX_DEBUG_ONLY(assert_valid();) 128279377Simp} 129279377Simp 130279377SimpPB_DS_CLASS_T_DEC 131279377Simpvoid 132279377SimpPB_DS_CLASS_C_DEC:: 133279377Simpresize_imp(entry_array a_entries_resized, size_type old_size) 134279377Simp{ 135279377Simp for (size_type pos = 0; pos < old_size; ++pos) 136279377Simp if (m_entries[pos].m_stat == valid_entry_status) 137279377Simp resize_imp_reassign(m_entries + pos, a_entries_resized, 138279377Simp traits_base::m_store_extra_indicator); 139279377Simp} 140279377Simp 141279377Simp#include <ext/pb_ds/detail/gp_hash_table_map_/resize_no_store_hash_fn_imps.hpp> 142279377Simp#include <ext/pb_ds/detail/gp_hash_table_map_/resize_store_hash_fn_imps.hpp> 143279377Simp 144279377Simp