3 // Copyright (C) 2005 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
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
32 // Permission to use, copy, modify, sell, and distribute this software
33 // is hereby granted without fee, provided that the above copyright
34 // notice appears in all copies, and that both that copyright notice and
35 // this permission notice appear in supporting documentation. None of
36 // the above authors, nor IBM Haifa Research Laboratories, make any
37 // representation about the suitability of this software for any
38 // purpose. It is provided "as is" without express or implied warranty.
41 * @file cc_hash_max_collision_check_resize_trigger_imp.hpp
42 * Contains an implementation of cc_hash_max_collision_check_resize_trigger.
46 pb_assoc::detail::int_to_type<External_Load_Access>
47 PB_ASSOC_CLASS_C_DEC::s_external_load_access_ind;
50 PB_ASSOC_CLASS_C_DEC::
51 cc_hash_max_collision_check_resize_trigger(float load) :
56 m_resize_needed(false)
61 PB_ASSOC_CLASS_C_DEC::
62 notify_find_search_start()
67 PB_ASSOC_CLASS_C_DEC::
68 notify_find_search_collision()
73 PB_ASSOC_CLASS_C_DEC::
74 notify_find_search_end()
79 PB_ASSOC_CLASS_C_DEC::
80 notify_insert_search_start()
87 PB_ASSOC_CLASS_C_DEC::
88 notify_insert_search_collision()
95 PB_ASSOC_CLASS_C_DEC::
96 notify_insert_search_end()
98 PB_ASSOC_DBG_ASSERT(NOTHING_HT_RESIZE_ACTION == 0);
101 m_resize_needed || (m_num_col >= m_max_col);
106 PB_ASSOC_CLASS_C_DEC::
107 notify_erase_search_start()
112 PB_ASSOC_CLASS_C_DEC::
113 notify_erase_search_collision()
118 PB_ASSOC_CLASS_C_DEC::
119 notify_erase_search_end()
124 PB_ASSOC_CLASS_C_DEC::
125 notify_inserted(size_type num_e)
127 PB_ASSOC_DBG_ASSERT(num_e <= m_size);
130 m_resize_needed = true;
135 PB_ASSOC_CLASS_C_DEC::
136 notify_erased(size_type num_e)
138 PB_ASSOC_DBG_ASSERT(num_e <= m_size);
140 m_resize_needed = false;
145 PB_ASSOC_CLASS_C_DEC::
148 m_resize_needed = false;
153 PB_ASSOC_CLASS_C_DEC::
154 is_resize_needed() const
156 return (m_resize_needed);
161 PB_ASSOC_CLASS_C_DEC::
162 is_grow_needed(size_type /*size*/, size_type /*num_used_e*/) const
164 PB_ASSOC_DBG_ASSERT(m_resize_needed);
171 PB_ASSOC_CLASS_C_DEC::
172 is_shrink_needed(size_type size, size_type num_used_e) const
174 PB_ASSOC_DBG_ASSERT(m_resize_needed);
181 PB_ASSOC_CLASS_C_DEC::
182 notify_resized(size_type new_size)
186 // max_col <-- \sqrt{2 load \ln( 2 m \ln( m ) ) }
188 const double ln_arg = 2* m_size* ::log( (double)m_size);
190 m_max_col = (size_type)::ceil( ::sqrt(2* m_load* ::log(ln_arg) ) );
194 m_resize_needed = false;
199 PB_ASSOC_CLASS_C_DEC::
200 notify_externally_resized(size_type new_size)
202 notify_resized(new_size);
207 PB_ASSOC_CLASS_C_DEC::
208 swap(PB_ASSOC_CLASS_C_DEC& r_other)
210 std::swap(m_load, r_other.m_load);
212 std::swap(m_size, r_other.m_size);
214 std::swap(m_num_col, r_other.m_num_col);
216 std::swap(m_max_col, r_other.m_max_col);
218 std::swap(m_resize_needed, r_other.m_resize_needed);
223 PB_ASSOC_CLASS_C_DEC::
224 get_load_imp(pb_assoc::detail::int_to_type<true>) const