standard_policies.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 
00045 #ifndef STANDARD_POLICIES_HPP
00046 #define STANDARD_POLICIES_HPP
00047 
00048 #include <memory>
00049 #include <ext/pb_assoc/hash_policy.hpp>
00050 #include <ext/pb_assoc/lu_policy.hpp>
00051 #include <ext/pb_assoc/tree_policy.hpp>
00052 #if defined(__GNUC__)
00053 #include <ext/hash_map>
00054 #elif defined(_MSC_VER)
00055 #include <hash_map>
00056 #else
00057 #error "Unable to determine the namespaces for your compiler. Please" \
00058     "Contact pbassoc@gmail.com"
00059 #endif // #if defined(__GNUC__)
00060 
00061 namespace pb_assoc
00062 {
00063 
00064   namespace detail
00065   {
00066 
00067 #ifdef __GNUC__
00068 
00069 #define PB_ASSOC_HASH_NAMESPACE \
00070     __gnu_cxx
00071 
00072     template<typename Key>
00073     struct def_hash_fn
00074     {
00075       typedef PB_ASSOC_HASH_NAMESPACE::hash<Key> type;
00076     };
00077 
00078     template<typename Key>
00079     struct def_eq_fn
00080     {
00081       typedef PB_ASSOC_HASH_NAMESPACE::equal_to<Key> type;
00082     };
00083 
00084 #elif defined(_MSC_VER)
00085 
00086     template<typename Key>
00087     struct hash_value_class_adapter
00088     {
00089       inline size_t
00090       operator()(const Key& r_key) const
00091       {
00092     return (stdext::hash_value(r_key));
00093       }
00094     };
00095 
00096     template<typename Key>
00097     struct def_hash_fn
00098     {
00099       typedef hash_value_class_adapter<Key> type;
00100     };
00101 
00102     template<typename Key>
00103     struct def_eq_fn
00104     {
00105       typedef std::equal_to<Key> type;
00106     };
00107 
00108 #else // #elif defined(_MSC_VER)
00109 
00110 #error Sorry, cannot determine headers, namespaces, etc. for your compiler.
00111 #error If you encounter this error, pls write to pbassoc@gmail.com
00112 
00113 #endif // #elif defined(_MSC_VER)
00114 
00115     enum
00116       {
00117     def_store_hash = false
00118       };
00119 
00120     struct def_comb_hash_fn
00121     {
00122       typedef pb_assoc::direct_mask_range_hashing<> type;
00123     };
00124 
00125     template<class Comb_Hash_Fn>
00126     struct def_resize_policy
00127     {
00128     private:
00129       typedef typename Comb_Hash_Fn::size_type size_type;
00130 
00131       typedef
00132       typename pb_assoc::detail::cond_type<
00133     pb_assoc::detail::is_same_type<
00134     pb_assoc::direct_mask_range_hashing<size_type>,
00135     Comb_Hash_Fn>::value,
00136     pb_assoc::hash_exponential_size_policy<
00137     size_type>,
00138     pb_assoc::hash_prime_size_policy>::type
00139       size_policy_type;
00140 
00141     public:
00142       typedef
00143       pb_assoc::hash_standard_resize_policy<
00144     size_policy_type,
00145     pb_assoc::hash_load_check_resize_trigger<
00146     false,
00147     size_type>,
00148     false,
00149     size_type>
00150       type;
00151     };
00152 
00153     struct def_update_policy
00154     {
00155       typedef pb_assoc::move_to_front_lu_policy<> type;
00156     };
00157 
00158 #ifdef __GNUC__
00159 #undef PB_ASSOC_HASH_NAMESPACE
00160 #endif // #ifdef __GNUC__
00161 
00162     template<class Comb_Probe_Fn>
00163     struct def_probe_fn
00164     {
00165     private:
00166       typedef typename Comb_Probe_Fn::size_type size_type;
00167 
00168     public:
00169       typedef
00170       typename pb_assoc::detail::cond_type<
00171     pb_assoc::detail::is_same_type<
00172     pb_assoc::direct_mask_range_hashing<size_t>,
00173     Comb_Probe_Fn>::value,
00174     pb_assoc::linear_probe_fn<
00175     size_type>,
00176     pb_assoc::quadratic_probe_fn<
00177     size_type> >::type
00178       type;
00179     };
00180 
00181     typedef pb_assoc::null_node_updator def_node_updator;
00182 
00183   } // namespace detail
00184 
00185 } // namespace pb_assoc
00186 
00187 #endif // #ifndef STANDARD_POLICIES_HPP
00188 

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