3 // Copyright (C) 2005-2023 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 cc_hash_max_collision_check_resize_trigger_imp.hpp
38 * Contains a resize trigger implementation.
41 #ifdef PB_DS_CLASS_C_DEC
45 cc_hash_max_collision_check_resize_trigger(float load) :
50 m_resize_needed(false)
56 notify_find_search_start()
62 notify_find_search_collision()
68 notify_find_search_end()
74 notify_insert_search_start()
80 notify_insert_search_collision()
86 notify_insert_search_end()
87 { calc_resize_needed(); }
92 notify_erase_search_start()
98 notify_erase_search_collision()
104 notify_erase_search_end()
110 notify_inserted(size_type)
116 notify_erased(size_type)
117 { m_resize_needed = true; }
123 { m_resize_needed = false; }
128 is_resize_needed() const
129 { return m_resize_needed; }
134 is_grow_needed(size_type /*size*/, size_type /*num_used_e*/) const
135 { return m_num_col >= m_max_col; }
140 notify_resized(size_type new_size)
144 #ifdef PB_DS_HT_MAP_RESIZE_TRACE_
145 std::cerr << "chmccrt::notify_resized "
146 << static_cast<unsigned long>(new_size) << std::endl;
150 calc_resize_needed();
159 // max_col <-- \sqrt{2 load \ln( 2 m \ln( m ) ) }
160 const double ln_arg = 2 * m_size * std::log(double(m_size));
161 m_max_col = size_type(std::ceil(std::sqrt(2 * m_load * std::log(ln_arg))));
163 #ifdef PB_DS_HT_MAP_RESIZE_TRACE_
164 std::cerr << "chmccrt::calc_max_num_coll "
165 << static_cast<unsigned long>(m_size) << " "
166 << static_cast<unsigned long>(m_max_col) << std::endl;
173 notify_externally_resized(size_type new_size)
174 { notify_resized(new_size); }
179 swap(PB_DS_CLASS_C_DEC& other)
181 std::swap(m_load, other.m_load);
182 std::swap(m_size, other.m_size);
183 std::swap(m_num_col, other.m_num_col);
184 std::swap(m_max_col, other.m_max_col);
185 std::swap(m_resize_needed, other.m_resize_needed);
193 PB_DS_STATIC_ASSERT(access, external_load_access);
201 { m_resize_needed = m_resize_needed || m_num_col >= m_max_col; }
208 PB_DS_STATIC_ASSERT(access, external_load_access);
211 calc_resize_needed();