1219820Sjeff// -*- C++ -*- 2272027Shselasky 3219820Sjeff// Copyright (C) 2005, 2006 Free Software Foundation, Inc. 4219820Sjeff// 5219820Sjeff// This file is part of the GNU ISO C++ Library. This library is free 6219820Sjeff// software; you can redistribute it and/or modify it under the terms 7219820Sjeff// of the GNU General Public License as published by the Free Software 8219820Sjeff// Foundation; either version 2, or (at your option) any later 9219820Sjeff// version. 10219820Sjeff 11219820Sjeff// This library is distributed in the hope that it will be useful, but 12219820Sjeff// WITHOUT ANY WARRANTY; without even the implied warranty of 13219820Sjeff// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14219820Sjeff// General Public License for more details. 15219820Sjeff 16219820Sjeff// You should have received a copy of the GNU General Public License 17219820Sjeff// along with this library; see the file COPYING. If not, write to 18219820Sjeff// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, 19219820Sjeff// MA 02111-1307, USA. 20219820Sjeff 21219820Sjeff// As a special exception, you may use this file as part of a free 22219820Sjeff// software library without restriction. Specifically, if other files 23219820Sjeff// instantiate templates or use macros or inline functions from this 24219820Sjeff// file, or you compile this file and link it with other files to 25219820Sjeff// produce an executable, this file does not by itself cause the 26219820Sjeff// resulting executable to be covered by the GNU General Public 27219820Sjeff// License. This exception does not however invalidate any other 28219820Sjeff// reasons why the executable file might be covered by the GNU General 29219820Sjeff// Public License. 30219820Sjeff 31219820Sjeff// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. 32219820Sjeff 33219820Sjeff// Permission to use, copy, modify, sell, and distribute this software 34272027Shselasky// is hereby granted without fee, provided that the above copyright 35219820Sjeff// notice appears in all copies, and that both that copyright notice 36219820Sjeff// and this permission notice appear in supporting documentation. None 37219820Sjeff// of the above authors, nor IBM Haifa Research Laboratories, make any 38219820Sjeff// representation about the suitability of this software for any 39219820Sjeff// purpose. It is provided "as is" without express or implied 40272027Shselasky// warranty. 41272027Shselasky 42272027Shselasky/** 43219820Sjeff * @file resize_fn_imps.hpp 44272027Shselasky * Contains implementations of gp_ht_map_'s resize related functions. 45272027Shselasky */ 46219820Sjeff 47219820SjeffPB_DS_CLASS_T_DEC 48219820Sjeffinline bool 49272027ShselaskyPB_DS_CLASS_C_DEC:: 50272027Shselaskydo_resize_if_needed() 51272027Shselasky{ 52272027Shselasky if (!resize_base::is_resize_needed()) 53219820Sjeff return false; 54219820Sjeff resize_imp(resize_base::get_new_size(m_num_e, m_num_used_e)); 55219820Sjeff return true; 56219820Sjeff} 57219820Sjeff 58219820SjeffPB_DS_CLASS_T_DEC 59219820Sjeffvoid 60272027ShselaskyPB_DS_CLASS_C_DEC:: 61272027Shselaskydo_resize(size_type n) 62272027Shselasky{ resize_imp(resize_base::get_nearest_larger_size(n)); } 63296987Shselasky 64272027ShselaskyPB_DS_CLASS_T_DEC 65272027Shselaskyinline void 66296987ShselaskyPB_DS_CLASS_C_DEC:: 67296987Shselaskydo_resize_if_needed_no_throw() 68272027Shselasky{ 69272027Shselasky if (!resize_base::is_resize_needed()) 70272027Shselasky return; 71272027Shselasky 72219820Sjeff try 73219820Sjeff { 74219820Sjeff resize_imp(resize_base::get_new_size(m_num_e, m_num_used_e)); 75219820Sjeff } 76219820Sjeff catch(...) 77219820Sjeff { } 78219820Sjeff 79219820Sjeff _GLIBCXX_DEBUG_ONLY(assert_valid();) 80219820Sjeff} 81219820Sjeff 82219820SjeffPB_DS_CLASS_T_DEC 83219820Sjeffvoid 84219820SjeffPB_DS_CLASS_C_DEC:: 85219820Sjeffresize_imp(size_type new_size) 86219820Sjeff{ 87219820Sjeff#ifdef PB_DS_REGRESSION 88219820Sjeff typename Allocator::group_throw_prob_adjustor adjust(m_num_e); 89272027Shselasky#endif 90272027Shselasky 91219820Sjeff if (new_size == m_num_e) 92219820Sjeff return; 93219820Sjeff 94219820Sjeff _GLIBCXX_DEBUG_ONLY(assert_valid();) 95219820Sjeff const size_type old_size = m_num_e; 96219820Sjeff entry_array a_entries_resized = NULL; 97219820Sjeff 98234099Sjhb // Following line might throw an exception. 99234099Sjhb a_entries_resized = s_entry_allocator.allocate(new_size); 100219820Sjeff 101234099Sjhb ranged_probe_fn_base::notify_resized(new_size); 102234099Sjhb m_num_e = new_size; 103234099Sjhb 104219820Sjeff for (size_type i = 0; i < m_num_e; ++i) 105234099Sjhb a_entries_resized[i].m_stat = empty_entry_status; 106272027Shselasky 107272027Shselasky try 108272027Shselasky { 109234099Sjhb resize_imp(a_entries_resized, old_size); 110234099Sjhb } 111234099Sjhb catch(...) 112272027Shselasky { 113272027Shselasky erase_all_valid_entries(a_entries_resized, new_size); 114272027Shselasky m_num_e = old_size; 115234099Sjhb s_entry_allocator.deallocate(a_entries_resized, new_size); 116234099Sjhb ranged_probe_fn_base::notify_resized(old_size); 117234099Sjhb __throw_exception_again; 118234099Sjhb } 119219820Sjeff 120272027Shselasky // At this point no exceptions can be thrown. 121219820Sjeff _GLIBCXX_DEBUG_ONLY(assert_entry_array_valid(a_entries_resized, traits_base::m_store_extra_indicator);) 122219820Sjeff 123219820Sjeff Resize_Policy::notify_resized(new_size); 124219820Sjeff erase_all_valid_entries(m_entries, old_size); 125219820Sjeff s_entry_allocator.deallocate(m_entries, old_size); 126219820Sjeff m_entries = a_entries_resized; 127272027Shselasky _GLIBCXX_DEBUG_ONLY(assert_valid();) 128219820Sjeff} 129272027Shselasky 130272027ShselaskyPB_DS_CLASS_T_DEC 131272027Shselaskyvoid 132272027ShselaskyPB_DS_CLASS_C_DEC:: 133272027Shselaskyresize_imp(entry_array a_entries_resized, size_type old_size) 134272027Shselasky{ 135272027Shselasky for (size_type pos = 0; pos < old_size; ++pos) 136219820Sjeff if (m_entries[pos].m_stat == valid_entry_status) 137272027Shselasky resize_imp_reassign(m_entries + pos, a_entries_resized, 138272027Shselasky traits_base::m_store_extra_indicator); 139272027Shselasky} 140272027Shselasky 141272027Shselasky#include <ext/pb_ds/detail/gp_hash_table_map_/resize_no_store_hash_fn_imps.hpp> 142219820Sjeff#include <ext/pb_ds/detail/gp_hash_table_map_/resize_store_hash_fn_imps.hpp> 143272027Shselasky 144272027Shselasky