hash_prime_size_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_prime_size_policy_imp.hpp
00042  * Contains an implementation of hash_prime_size_policy.
00043  */
00044 
00045 namespace detail
00046 {
00047 
00048   enum
00049     {
00050       num_distinct_sizes = 28
00051     };
00052 
00053   static const size_t s_a_sizes[num_distinct_sizes] =
00054     {
00055       /* Dealing cards... */
00056       /* 0  */ 53ul,
00057       /* 1  */ 97ul,
00058       /* 2  */ 193ul,
00059       /* 3  */ 389ul,
00060       /* 4  */ 769ul,
00061       /* 5  */ 1543ul,
00062       /* 6  */ 3079ul,
00063       /* 7  */ 6151ul,
00064       /* 8  */ 12289ul,
00065       /* 9  */ 24593ul,
00066       /* 10 */ 49157ul,
00067       /* 11 */ 98317ul,
00068       /* 12 */ 196613ul,
00069       /* 13 */ 393241ul,
00070       /* 14 */ 786433ul,
00071       /* 15 */ 1572869ul,
00072       /* 16 */ 3145739ul,
00073       /* 17 */ 6291469ul,
00074       /* 18 */ 12582917ul,
00075       /* 19 */ 25165843ul,
00076       /* 20 */ 50331653ul,
00077       /* 21 */ 100663319ul,
00078       /* 22 */ 201326611ul,
00079       /* 23 */ 402653189ul,
00080       /* 24 */ 805306457ul,
00081       /* 25 */ 1610612741,
00082       /* 26 */ 3221225473ul,
00083       /* 27 */ 4294967291ul
00084       /* Pot's good, let's play */
00085     };
00086 
00087 } // namespace detail
00088 
00089 PB_ASSOC_CLASS_T_DEC
00090 inline void
00091 PB_ASSOC_CLASS_C_DEC::
00092 swap(PB_ASSOC_CLASS_C_DEC& /*r_other*/)
00093 { }
00094 
00095 PB_ASSOC_CLASS_T_DEC
00096 PB_ASSOC_CLASS_C_DEC::size_type
00097 PB_ASSOC_CLASS_C_DEC::
00098 get_init_size(size_type suggested_size) const
00099 {
00100   return (get_nearest_larger_size_imp(suggested_size));
00101 }
00102 
00103 PB_ASSOC_CLASS_T_DEC
00104 inline PB_ASSOC_CLASS_C_DEC::size_type
00105 PB_ASSOC_CLASS_C_DEC::
00106 get_nearest_larger_size(size_type cur_size) const
00107 {
00108   PB_ASSOC_DBG_ONLY(assert_is_one_of_my_sizes(cur_size);)
00109 
00110     return (get_nearest_larger_size_imp(cur_size));
00111 }
00112 
00113 PB_ASSOC_CLASS_T_DEC
00114 inline PB_ASSOC_CLASS_C_DEC::size_type
00115 PB_ASSOC_CLASS_C_DEC::
00116 get_nearest_smaller_size(size_type cur_size) const
00117 {
00118   PB_ASSOC_DBG_ONLY(assert_is_one_of_my_sizes(cur_size);)
00119 
00120     return (*std::lower_bound(detail::s_a_sizes, detail::s_a_sizes + detail::num_distinct_sizes, cur_size - 1));
00121 }
00122 
00123 PB_ASSOC_CLASS_T_DEC
00124 inline PB_ASSOC_CLASS_C_DEC::size_type
00125 PB_ASSOC_CLASS_C_DEC::
00126 get_nearest_larger_size_imp(size_type size) const
00127 {
00128   const size_t* const p_upper =
00129     std::upper_bound(detail::s_a_sizes, detail::s_a_sizes + detail::num_distinct_sizes, size);
00130 
00131   return ((p_upper == detail::s_a_sizes + detail::num_distinct_sizes)?
00132       size :
00133       *p_upper);
00134 }
00135 
00136 #ifdef PB_ASSOC_HT_PRIME_SIZE_POLICY_DEBUG
00137 PB_ASSOC_CLASS_T_DEC
00138 void
00139 PB_ASSOC_CLASS_C_DEC::
00140 assert_is_one_of_my_sizes(size_type size)
00141 {
00142   const size_t* const p_end =
00143     detail::s_a_sizes + detail::num_distinct_sizes;
00144 
00145   const size_t* const p_found =
00146     std::find(detail::s_a_sizes, p_end, size)
00147 
00148     PB_ASSOC_DBG_ASSERT(p_found != p_end);
00149 }
00150 #endif // #ifdef PB_ASSOC_HT_PRIME_SIZE_POLICY_DEBUG

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