3 // Copyright (C) 2005, 2006 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 2, 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 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING. If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 // MA 02111-1307, USA.
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction. Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License. This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
31 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
33 // Permission to use, copy, modify, sell, and distribute this software
34 // is hereby granted without fee, provided that the above copyright
35 // notice appears in all copies, and that both that copyright notice
36 // and this permission notice appear in supporting documentation. None
37 // of the above authors, nor IBM Haifa Research Laboratories, make any
38 // representation about the suitability of this software for any
39 // purpose. It is provided "as is" without express or implied
43 * @file hash_standard_resize_policy_imp.hpp
44 * Contains a resize policy implementation.
47 #define PB_DS_STATIC_ASSERT(UNIQUE, E) \
48 typedef detail::static_assert_dumclass<sizeof(detail::static_assert<(bool)(E)>)> UNIQUE##static_assert_type
52 hash_standard_resize_policy()
53 : m_size(Size_Policy::get_nearest_larger_size(1))
54 { trigger_policy_base::notify_externally_resized(m_size); }
58 hash_standard_resize_policy(const Size_Policy& r_size_policy)
59 : Size_Policy(r_size_policy), m_size(Size_Policy::get_nearest_larger_size(1))
60 { trigger_policy_base::notify_externally_resized(m_size); }
64 hash_standard_resize_policy(const Size_Policy& r_size_policy,
65 const Trigger_Policy& r_trigger_policy)
66 : Size_Policy(r_size_policy), Trigger_Policy(r_trigger_policy),
67 m_size(Size_Policy::get_nearest_larger_size(1))
68 { trigger_policy_base::notify_externally_resized(m_size); }
72 ~hash_standard_resize_policy()
78 swap(PB_DS_CLASS_C_DEC& other)
80 trigger_policy_base::swap(other);
81 size_policy_base::swap(other);
82 std::swap(m_size, other.m_size);
88 notify_find_search_start()
89 { trigger_policy_base::notify_find_search_start(); }
94 notify_find_search_collision()
95 { trigger_policy_base::notify_find_search_collision(); }
100 notify_find_search_end()
101 { trigger_policy_base::notify_find_search_end(); }
106 notify_insert_search_start()
107 { trigger_policy_base::notify_insert_search_start(); }
112 notify_insert_search_collision()
113 { trigger_policy_base::notify_insert_search_collision(); }
118 notify_insert_search_end()
119 { trigger_policy_base::notify_insert_search_end(); }
124 notify_erase_search_start()
125 { trigger_policy_base::notify_erase_search_start(); }
130 notify_erase_search_collision()
131 { trigger_policy_base::notify_erase_search_collision(); }
136 notify_erase_search_end()
137 { trigger_policy_base::notify_erase_search_end(); }
142 notify_inserted(size_type num_e)
143 { trigger_policy_base::notify_inserted(num_e); }
148 notify_erased(size_type num_e)
149 { trigger_policy_base::notify_erased(num_e); }
155 { trigger_policy_base::notify_cleared(); }
160 is_resize_needed() const
161 { return trigger_policy_base::is_resize_needed(); }
164 typename PB_DS_CLASS_C_DEC::size_type
166 get_new_size(size_type size, size_type num_used_e) const
168 if (trigger_policy_base::is_grow_needed(size, num_used_e))
169 return size_policy_base::get_nearest_larger_size(size);
170 return size_policy_base::get_nearest_smaller_size(size);
176 notify_resized(size_type new_size)
178 trigger_policy_base::notify_resized(new_size);
183 inline typename PB_DS_CLASS_C_DEC::size_type
185 get_actual_size() const
187 PB_DS_STATIC_ASSERT(access, external_size_access);
194 resize(size_type new_size)
196 PB_DS_STATIC_ASSERT(access, external_size_access);
197 size_type actual_size = size_policy_base::get_nearest_larger_size(1);
198 while (actual_size < new_size)
200 const size_type pot = size_policy_base::get_nearest_larger_size(actual_size);
202 if (pot == actual_size && pot < new_size)
203 __throw_resize_error();
210 const size_type old_size = m_size;
213 do_resize(actual_size - 1);
215 catch(insert_error& )
218 __throw_resize_error();
223 __throw_exception_again;
242 const Trigger_Policy&
244 get_trigger_policy() const
256 get_size_policy() const
259 #undef PB_DS_STATIC_ASSERT