hash_standard_resize_policy_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 hash_standard_resize_policy_imp.hpp
00042  * Contains an implementation of hash_standard_resize_policy.
00043  */
00044 
00045 #ifdef PB_ASSOC_HT_STANDARD_RESIZE_POLICY_DEBUG
00046 #define PB_ASSOC_DBG_ASSERT(X) assert(X)
00047 #define PB_ASSOC_DBG_VERIFY(X) assert(X)
00048 #define PB_ASSOC_DBG_ONLY(X) X
00049 #else // #ifdef PB_ASSOC_HT_STANDARD_RESIZE_POLICY_DEBUG
00050 #define PB_ASSOC_DBG_ASSERT(X)
00051 #define PB_ASSOC_DBG_VERIFY(X) {if((X)==0);}
00052 #define PB_ASSOC_DBG_ONLY(X) ;
00053 #endif // #ifdef PB_ASSOC_HT_STANDARD_RESIZE_POLICY_DEBUG
00054 
00055 PB_ASSOC_CLASS_T_DEC
00056 pb_assoc::detail::int_to_type<External_Size_Access>
00057 PB_ASSOC_CLASS_C_DEC::s_external_size_access_indicator;
00058 
00059 PB_ASSOC_CLASS_T_DEC
00060 PB_ASSOC_CLASS_C_DEC::
00061 hash_standard_resize_policy(size_type suggested_size /*= 8*/) :
00062   m_size(Size_Policy::get_init_size(suggested_size))
00063 {
00064   my_trigger_policy_base::notify_externally_resized(
00065                             Size_Policy::get_init_size(suggested_size));
00066 }
00067 
00068 PB_ASSOC_CLASS_T_DEC
00069 PB_ASSOC_CLASS_C_DEC::
00070 hash_standard_resize_policy(const Size_Policy& r_size_policy, size_type suggested_size /*= 8*/) :
00071   Size_Policy(r_size_policy),
00072   m_size(Size_Policy::get_init_size(suggested_size))
00073 { }
00074 
00075 PB_ASSOC_CLASS_T_DEC
00076 PB_ASSOC_CLASS_C_DEC::
00077 hash_standard_resize_policy(const Size_Policy& r_size_policy, const Trigger_Policy& r_trigger_policy, size_type suggested_size /*= 8*/) :
00078   Size_Policy(r_size_policy),
00079   Trigger_Policy(r_trigger_policy),
00080   m_size(Size_Policy::get_init_size(suggested_size))
00081 { }
00082 
00083 PB_ASSOC_CLASS_T_DEC
00084 PB_ASSOC_CLASS_C_DEC::
00085 ~hash_standard_resize_policy()
00086 { }
00087 
00088 PB_ASSOC_CLASS_T_DEC
00089 void
00090 PB_ASSOC_CLASS_C_DEC::
00091 swap(PB_ASSOC_CLASS_C_DEC& r_other)
00092 {
00093   my_trigger_policy_base::swap(r_other);
00094 
00095   my_size_policy_base::swap(r_other);
00096 
00097   std::swap(m_size, r_other.m_size);
00098 }
00099 
00100 PB_ASSOC_CLASS_T_DEC
00101 inline void
00102 PB_ASSOC_CLASS_C_DEC::
00103 notify_find_search_start()
00104 {
00105   my_trigger_policy_base::notify_find_search_start();
00106 }
00107 
00108 PB_ASSOC_CLASS_T_DEC
00109 inline void
00110 PB_ASSOC_CLASS_C_DEC::
00111 notify_find_search_collision()
00112 {
00113   my_trigger_policy_base::notify_find_search_collision();
00114 }
00115 
00116 PB_ASSOC_CLASS_T_DEC
00117 inline void
00118 PB_ASSOC_CLASS_C_DEC::
00119 notify_find_search_end()
00120 {
00121   my_trigger_policy_base::notify_find_search_end();
00122 }
00123 
00124 PB_ASSOC_CLASS_T_DEC
00125 inline void
00126 PB_ASSOC_CLASS_C_DEC::
00127 notify_insert_search_start()
00128 {
00129   my_trigger_policy_base::notify_insert_search_start();
00130 }
00131 
00132 PB_ASSOC_CLASS_T_DEC
00133 inline void
00134 PB_ASSOC_CLASS_C_DEC::
00135 notify_insert_search_collision()
00136 {
00137   my_trigger_policy_base::notify_insert_search_collision();
00138 }
00139 
00140 PB_ASSOC_CLASS_T_DEC
00141 inline void
00142 PB_ASSOC_CLASS_C_DEC::
00143 notify_insert_search_end()
00144 {
00145   my_trigger_policy_base::notify_insert_search_end();
00146 }
00147 
00148 PB_ASSOC_CLASS_T_DEC
00149 inline void
00150 PB_ASSOC_CLASS_C_DEC::
00151 notify_erase_search_start()
00152 {
00153   my_trigger_policy_base::notify_erase_search_start();
00154 }
00155 
00156 PB_ASSOC_CLASS_T_DEC
00157 inline void
00158 PB_ASSOC_CLASS_C_DEC::
00159 notify_erase_search_collision()
00160 {
00161   my_trigger_policy_base::notify_erase_search_collision();
00162 }
00163 
00164 PB_ASSOC_CLASS_T_DEC
00165 inline void
00166 PB_ASSOC_CLASS_C_DEC::
00167 notify_erase_search_end()
00168 {
00169   my_trigger_policy_base::notify_erase_search_end();
00170 }
00171 
00172 PB_ASSOC_CLASS_T_DEC
00173 inline void
00174 PB_ASSOC_CLASS_C_DEC::
00175 notify_inserted(size_type num_e)
00176 {
00177   my_trigger_policy_base::notify_inserted(num_e);
00178 }
00179 
00180 PB_ASSOC_CLASS_T_DEC
00181 inline void
00182 PB_ASSOC_CLASS_C_DEC::
00183 notify_erased(size_type num_e)
00184 {
00185   my_trigger_policy_base::notify_inserted(num_e);
00186 }
00187 
00188 PB_ASSOC_CLASS_T_DEC
00189 void
00190 PB_ASSOC_CLASS_C_DEC::
00191 notify_cleared()
00192 {
00193   my_trigger_policy_base::notify_cleared();
00194 }
00195 
00196 PB_ASSOC_CLASS_T_DEC
00197 inline bool
00198 PB_ASSOC_CLASS_C_DEC::
00199 is_resize_needed() const
00200 {
00201   return (my_trigger_policy_base::is_resize_needed());
00202 }
00203 
00204 PB_ASSOC_CLASS_T_DEC
00205 typename PB_ASSOC_CLASS_C_DEC::size_type
00206 PB_ASSOC_CLASS_C_DEC::
00207 get_new_size(size_type size, size_type num_used_e) const
00208 {
00209   PB_ASSOC_DBG_ASSERT(m_size == size);
00210 
00211   if (my_trigger_policy_base::
00212       is_grow_needed(size, num_used_e))
00213     return (my_size_policy_base::get_nearest_larger_size(m_size));
00214 
00215   PB_ASSOC_DBG_ASSERT(my_trigger_policy_base::
00216               is_shrink_needed(size, num_used_e));
00217 
00218   return (my_size_policy_base::get_nearest_smaller_size(m_size));
00219 }
00220 
00221 PB_ASSOC_CLASS_T_DEC
00222 typename PB_ASSOC_CLASS_C_DEC::size_type
00223 PB_ASSOC_CLASS_C_DEC::
00224 get_init_size() const
00225 {
00226   PB_ASSOC_DBG_ASSERT(m_size ==
00227               my_trigger_policy_base::get_init_size());
00228 
00229   return (m_size);
00230 }
00231 
00232 PB_ASSOC_CLASS_T_DEC
00233 void
00234 PB_ASSOC_CLASS_C_DEC::
00235 notify_resized(size_type new_size)
00236 {
00237   my_trigger_policy_base::notify_resized(new_size);
00238 
00239   m_size = new_size;
00240 }
00241 
00242 PB_ASSOC_CLASS_T_DEC
00243 inline typename PB_ASSOC_CLASS_C_DEC::size_type
00244 PB_ASSOC_CLASS_C_DEC::
00245 get_actual_size() const
00246 {
00247   return (get_actual_size(s_external_size_access_indicator));
00248 }
00249 
00250 PB_ASSOC_CLASS_T_DEC
00251 inline typename PB_ASSOC_CLASS_C_DEC::size_type
00252 PB_ASSOC_CLASS_C_DEC::
00253 get_actual_size(external_resize_true_indicator) const
00254 {
00255   return (m_size);
00256 }
00257 
00258 PB_ASSOC_CLASS_T_DEC
00259 void
00260 PB_ASSOC_CLASS_C_DEC::
00261 resize(size_type new_size)
00262 {
00263   resize(new_size, s_external_size_access_indicator);
00264 }
00265 
00266 PB_ASSOC_CLASS_T_DEC
00267 void
00268 PB_ASSOC_CLASS_C_DEC::
00269 resize(size_type new_size, external_resize_true_indicator)
00270 {
00271   size_type actual_new_size = my_size_policy_base::get_init_size(1);
00272   while (actual_new_size < new_size)
00273     {
00274       const size_type pot =
00275     my_size_policy_base::get_nearest_larger_size(actual_new_size);
00276 
00277       if (pot == actual_new_size&&  pot < new_size)
00278     throw cannot_resize();
00279 
00280       actual_new_size = pot;
00281     }
00282 
00283   const size_type old_size = m_size;
00284 
00285   try
00286     {
00287       do_resize(actual_new_size);
00288     }
00289   catch(cannot_insert& )
00290     {
00291       m_size = old_size;
00292 
00293       throw cannot_resize();
00294     }
00295   catch(...)
00296     {
00297       m_size = old_size;
00298 
00299       throw;
00300     }
00301 }
00302 
00303 PB_ASSOC_CLASS_T_DEC
00304 void
00305 PB_ASSOC_CLASS_C_DEC::
00306 do_resize(size_type /*new_size*/)
00307 {
00308   // Tmp Ami
00309   abort();
00310 }
00311 
00312 PB_ASSOC_CLASS_T_DEC
00313 Trigger_Policy& 
00314 PB_ASSOC_CLASS_C_DEC::
00315 get_trigger_policy()
00316 {
00317   return (*this);
00318 }
00319 
00320 PB_ASSOC_CLASS_T_DEC
00321 const Trigger_Policy& 
00322 PB_ASSOC_CLASS_C_DEC::
00323 get_trigger_policy() const
00324 {
00325   return (*this);
00326 }
00327 
00328 PB_ASSOC_CLASS_T_DEC
00329 Size_Policy& 
00330 PB_ASSOC_CLASS_C_DEC::
00331 get_size_policy()
00332 {
00333   return (*this);
00334 }
00335 
00336 PB_ASSOC_CLASS_T_DEC
00337 const Size_Policy& 
00338 PB_ASSOC_CLASS_C_DEC::
00339 get_size_policy() const
00340 {
00341   return (*this);
00342 }

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