3 // Copyright (C) 2005-2024 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 3, or (at your option) any later
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
27 // Permission to use, copy, modify, sell, and distribute this software
28 // is hereby granted without fee, provided that the above copyright
29 // notice appears in all copies, and that both that copyright notice
30 // and this permission notice appear in supporting documentation. None
31 // of the above authors, nor IBM Haifa Research Laboratories, make any
32 // representation about the suitability of this software for any
33 // purpose. It is provided "as is" without express or implied
37 * @file hash_standard_resize_policy_imp.hpp
38 * Contains a resize policy implementation.
41 #ifdef PB_DS_CLASS_C_DEC
45 hash_standard_resize_policy()
46 : m_size(Size_Policy::get_nearest_larger_size(1))
47 { trigger_policy_base::notify_externally_resized(m_size); }
51 hash_standard_resize_policy(const Size_Policy& r_size_policy)
52 : Size_Policy(r_size_policy), m_size(Size_Policy::get_nearest_larger_size(1))
53 { trigger_policy_base::notify_externally_resized(m_size); }
57 hash_standard_resize_policy(const Size_Policy& r_size_policy,
58 const Trigger_Policy& r_trigger_policy)
59 : Size_Policy(r_size_policy), Trigger_Policy(r_trigger_policy),
60 m_size(Size_Policy::get_nearest_larger_size(1))
61 { trigger_policy_base::notify_externally_resized(m_size); }
65 ~hash_standard_resize_policy()
71 swap(PB_DS_CLASS_C_DEC& other)
73 trigger_policy_base::swap(other);
74 size_policy_base::swap(other);
75 std::swap(m_size, other.m_size);
81 notify_find_search_start()
82 { trigger_policy_base::notify_find_search_start(); }
87 notify_find_search_collision()
88 { trigger_policy_base::notify_find_search_collision(); }
93 notify_find_search_end()
94 { trigger_policy_base::notify_find_search_end(); }
99 notify_insert_search_start()
100 { trigger_policy_base::notify_insert_search_start(); }
105 notify_insert_search_collision()
106 { trigger_policy_base::notify_insert_search_collision(); }
111 notify_insert_search_end()
112 { trigger_policy_base::notify_insert_search_end(); }
117 notify_erase_search_start()
118 { trigger_policy_base::notify_erase_search_start(); }
123 notify_erase_search_collision()
124 { trigger_policy_base::notify_erase_search_collision(); }
129 notify_erase_search_end()
130 { trigger_policy_base::notify_erase_search_end(); }
135 notify_inserted(size_type num_e)
136 { trigger_policy_base::notify_inserted(num_e); }
141 notify_erased(size_type num_e)
142 { trigger_policy_base::notify_erased(num_e); }
148 { trigger_policy_base::notify_cleared(); }
153 is_resize_needed() const
154 { return trigger_policy_base::is_resize_needed(); }
157 typename PB_DS_CLASS_C_DEC::size_type
159 get_new_size(size_type size, size_type num_used_e) const
161 if (trigger_policy_base::is_grow_needed(size, num_used_e))
162 return size_policy_base::get_nearest_larger_size(size);
163 return size_policy_base::get_nearest_smaller_size(size);
169 notify_resized(size_type new_size)
171 trigger_policy_base::notify_resized(new_size);
176 inline typename PB_DS_CLASS_C_DEC::size_type
178 get_actual_size() const
180 PB_DS_STATIC_ASSERT(access, external_size_access);
187 resize(size_type new_size)
189 PB_DS_STATIC_ASSERT(access, external_size_access);
190 size_type actual_size = size_policy_base::get_nearest_larger_size(1);
191 while (actual_size < new_size)
193 const size_type pot = size_policy_base::get_nearest_larger_size(actual_size);
195 if (pot == actual_size && pot < new_size)
196 __throw_resize_error();
203 const size_type old_size = m_size;
206 do_resize(actual_size - 1);
208 __catch(insert_error& )
211 __throw_resize_error();
216 __throw_exception_again;
235 const Trigger_Policy&
237 get_trigger_policy() const
249 get_size_policy() const