3 // Copyright (C) 2005-2013 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.
43 hash_standard_resize_policy()
44 : m_size(Size_Policy::get_nearest_larger_size(1))
45 { trigger_policy_base::notify_externally_resized(m_size); }
49 hash_standard_resize_policy(const Size_Policy& r_size_policy)
50 : Size_Policy(r_size_policy), m_size(Size_Policy::get_nearest_larger_size(1))
51 { trigger_policy_base::notify_externally_resized(m_size); }
55 hash_standard_resize_policy(const Size_Policy& r_size_policy,
56 const Trigger_Policy& r_trigger_policy)
57 : Size_Policy(r_size_policy), Trigger_Policy(r_trigger_policy),
58 m_size(Size_Policy::get_nearest_larger_size(1))
59 { trigger_policy_base::notify_externally_resized(m_size); }
63 ~hash_standard_resize_policy()
69 swap(PB_DS_CLASS_C_DEC& other)
71 trigger_policy_base::swap(other);
72 size_policy_base::swap(other);
73 std::swap(m_size, other.m_size);
79 notify_find_search_start()
80 { trigger_policy_base::notify_find_search_start(); }
85 notify_find_search_collision()
86 { trigger_policy_base::notify_find_search_collision(); }
91 notify_find_search_end()
92 { trigger_policy_base::notify_find_search_end(); }
97 notify_insert_search_start()
98 { trigger_policy_base::notify_insert_search_start(); }
103 notify_insert_search_collision()
104 { trigger_policy_base::notify_insert_search_collision(); }
109 notify_insert_search_end()
110 { trigger_policy_base::notify_insert_search_end(); }
115 notify_erase_search_start()
116 { trigger_policy_base::notify_erase_search_start(); }
121 notify_erase_search_collision()
122 { trigger_policy_base::notify_erase_search_collision(); }
127 notify_erase_search_end()
128 { trigger_policy_base::notify_erase_search_end(); }
133 notify_inserted(size_type num_e)
134 { trigger_policy_base::notify_inserted(num_e); }
139 notify_erased(size_type num_e)
140 { trigger_policy_base::notify_erased(num_e); }
146 { trigger_policy_base::notify_cleared(); }
151 is_resize_needed() const
152 { return trigger_policy_base::is_resize_needed(); }
155 typename PB_DS_CLASS_C_DEC::size_type
157 get_new_size(size_type size, size_type num_used_e) const
159 if (trigger_policy_base::is_grow_needed(size, num_used_e))
160 return size_policy_base::get_nearest_larger_size(size);
161 return size_policy_base::get_nearest_smaller_size(size);
167 notify_resized(size_type new_size)
169 trigger_policy_base::notify_resized(new_size);
174 inline typename PB_DS_CLASS_C_DEC::size_type
176 get_actual_size() const
178 PB_DS_STATIC_ASSERT(access, external_size_access);
185 resize(size_type new_size)
187 PB_DS_STATIC_ASSERT(access, external_size_access);
188 size_type actual_size = size_policy_base::get_nearest_larger_size(1);
189 while (actual_size < new_size)
191 const size_type pot = size_policy_base::get_nearest_larger_size(actual_size);
193 if (pot == actual_size && pot < new_size)
194 __throw_resize_error();
201 const size_type old_size = m_size;
204 do_resize(actual_size - 1);
206 __catch(insert_error& )
209 __throw_resize_error();
214 __throw_exception_again;
233 const Trigger_Policy&
235 get_trigger_policy() const
247 get_size_policy() const