cc_hash_max_collision_resize_trigger_imp.hpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2005 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 2, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // You should have received a copy of the GNU General Public License along
00017 // with this library; see the file COPYING.  If not, write to the Free
00018 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00019 // USA.
00020 
00021 // As a special exception, you may use this file as part of a free software
00022 // library without restriction.  Specifically, if other files instantiate
00023 // templates or use macros or inline functions from this file, or you compile
00024 // this file and link it with other files to produce an executable, this
00025 // file does not by itself cause the resulting executable to be covered by
00026 // the GNU General Public License.  This exception does not however
00027 // invalidate any other reasons why the executable file might be covered by
00028 // the GNU General Public License.
00029 
00030 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
00031 
00032 // Permission to use, copy, modify, sell, and distribute this software
00033 // is hereby granted without fee, provided that the above copyright
00034 // notice appears in all copies, and that both that copyright notice and
00035 // this permission notice appear in supporting documentation. None of
00036 // the above authors, nor IBM Haifa Research Laboratories, make any
00037 // representation about the suitability of this software for any
00038 // purpose. It is provided "as is" without express or implied warranty.
00039 
00040 /*
00041  * @file cc_hash_max_collision_check_resize_trigger_imp.hpp
00042  * Contains an implementation of cc_hash_max_collision_check_resize_trigger.
00043  */
00044 
00045 PB_ASSOC_CLASS_T_DEC
00046 pb_assoc::detail::int_to_type<External_Load_Access>
00047 PB_ASSOC_CLASS_C_DEC::s_external_load_access_ind;
00048 
00049 PB_ASSOC_CLASS_T_DEC
00050 PB_ASSOC_CLASS_C_DEC::
00051 cc_hash_max_collision_check_resize_trigger(float load) :
00052   m_load(load),
00053   m_size(0),
00054   m_num_col(0),
00055   m_max_col(0),
00056   m_resize_needed(false)
00057 { }
00058 
00059 PB_ASSOC_CLASS_T_DEC
00060 inline void
00061 PB_ASSOC_CLASS_C_DEC::
00062 notify_find_search_start()
00063 { }
00064 
00065 PB_ASSOC_CLASS_T_DEC
00066 inline void
00067 PB_ASSOC_CLASS_C_DEC::
00068 notify_find_search_collision()
00069 { }
00070 
00071 PB_ASSOC_CLASS_T_DEC
00072 inline void
00073 PB_ASSOC_CLASS_C_DEC::
00074 notify_find_search_end()
00075 { }
00076 
00077 PB_ASSOC_CLASS_T_DEC
00078 inline void
00079 PB_ASSOC_CLASS_C_DEC::
00080 notify_insert_search_start()
00081 {
00082   m_num_col = 0;
00083 }
00084 
00085 PB_ASSOC_CLASS_T_DEC
00086 inline void
00087 PB_ASSOC_CLASS_C_DEC::
00088 notify_insert_search_collision()
00089 {
00090   ++m_num_col;
00091 }
00092 
00093 PB_ASSOC_CLASS_T_DEC
00094 inline void
00095 PB_ASSOC_CLASS_C_DEC::
00096 notify_insert_search_end()
00097 {
00098   PB_ASSOC_DBG_ASSERT(NOTHING_HT_RESIZE_ACTION == 0);
00099 
00100   m_resize_needed =
00101     m_resize_needed || (m_num_col >= m_max_col);
00102 }
00103 
00104 PB_ASSOC_CLASS_T_DEC
00105 inline void
00106 PB_ASSOC_CLASS_C_DEC::
00107 notify_erase_search_start()
00108 { }
00109 
00110 PB_ASSOC_CLASS_T_DEC
00111 inline void
00112 PB_ASSOC_CLASS_C_DEC::
00113 notify_erase_search_collision()
00114 { }
00115 
00116 PB_ASSOC_CLASS_T_DEC
00117 inline void
00118 PB_ASSOC_CLASS_C_DEC::
00119 notify_erase_search_end()
00120 { }
00121 
00122 PB_ASSOC_CLASS_T_DEC
00123 inline void
00124 PB_ASSOC_CLASS_C_DEC::
00125 notify_inserted(size_type num_e)
00126 {
00127   PB_ASSOC_DBG_ASSERT(num_e <= m_size);
00128 
00129   if (num_e == m_size)
00130     m_resize_needed = true;
00131 }
00132 
00133 PB_ASSOC_CLASS_T_DEC
00134 inline void
00135 PB_ASSOC_CLASS_C_DEC::
00136 notify_erased(size_type num_e)
00137 {
00138   PB_ASSOC_DBG_ASSERT(num_e <= m_size);
00139 
00140   m_resize_needed = false;
00141 }
00142 
00143 PB_ASSOC_CLASS_T_DEC
00144 void
00145 PB_ASSOC_CLASS_C_DEC::
00146 notify_cleared()
00147 {
00148   m_resize_needed = false;
00149 }
00150 
00151 PB_ASSOC_CLASS_T_DEC
00152 inline bool
00153 PB_ASSOC_CLASS_C_DEC::
00154 is_resize_needed() const
00155 {
00156   return (m_resize_needed);
00157 }
00158 
00159 PB_ASSOC_CLASS_T_DEC
00160 inline bool
00161 PB_ASSOC_CLASS_C_DEC::
00162 is_grow_needed(size_type /*size*/, size_type /*num_used_e*/) const
00163 {
00164   PB_ASSOC_DBG_ASSERT(m_resize_needed);
00165 
00166   return (true);
00167 }
00168 
00169 PB_ASSOC_CLASS_T_DEC
00170 inline bool
00171 PB_ASSOC_CLASS_C_DEC::
00172 is_shrink_needed(size_type size, size_type num_used_e) const
00173 {
00174   PB_ASSOC_DBG_ASSERT(m_resize_needed);
00175 
00176   return (false);
00177 }
00178 
00179 PB_ASSOC_CLASS_T_DEC
00180 void
00181 PB_ASSOC_CLASS_C_DEC::
00182 notify_resized(size_type new_size)
00183 {
00184   m_size = new_size;
00185 
00186   // max_col <-- \sqrt{2 load \ln( 2 m \ln( m ) ) }
00187 
00188   const double ln_arg = 2*  m_size*  ::log( (double)m_size);
00189 
00190   m_max_col = (size_type)::ceil(  ::sqrt(2*   m_load*  ::log(ln_arg) ) );
00191 
00192   m_num_col = 0;
00193 
00194   m_resize_needed = false;
00195 }
00196 
00197 PB_ASSOC_CLASS_T_DEC
00198 void
00199 PB_ASSOC_CLASS_C_DEC::
00200 notify_externally_resized(size_type new_size)
00201 {
00202   notify_resized(new_size);
00203 }
00204 
00205 PB_ASSOC_CLASS_T_DEC
00206 void
00207 PB_ASSOC_CLASS_C_DEC::
00208 swap(PB_ASSOC_CLASS_C_DEC& r_other)
00209 {
00210   std::swap(m_load, r_other.m_load);
00211 
00212   std::swap(m_size, r_other.m_size);
00213 
00214   std::swap(m_num_col, r_other.m_num_col);
00215 
00216   std::swap(m_max_col, r_other.m_max_col);
00217 
00218   std::swap(m_resize_needed, r_other.m_resize_needed);
00219 }
00220 
00221 PB_ASSOC_CLASS_T_DEC
00222 inline float
00223 PB_ASSOC_CLASS_C_DEC::
00224 get_load_imp(pb_assoc::detail::int_to_type<true>) const
00225 {
00226   return (m_load);
00227 }

Generated on Tue Feb 2 16:55:49 2010 for GNU C++ STL by  doxygen 1.4.7