# standard_policies.hpp

Go to the documentation of this file.

    00001 // -*- C++ -*-
    00002
    00003 // Copyright (C) 2005, 2006, 2007 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 terms
    00007 // of the GNU General Public License as published by the Free Software
    00008 // Foundation; either version 2, or (at your option) any later
    00009 // version.
    00010
    00011 // This library is distributed in the hope that it will be useful, but
    00012 // WITHOUT ANY WARRANTY; without even the implied warranty of
    00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00014 // General Public License for more details.
    00015
    00016 // You should have received a copy of the GNU General Public License
    00017 // along with this library; see the file COPYING.  If not, write to
    00018 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
    00019 // MA 02111-1307, USA.
    00020
    00021 // As a special exception, you may use this file as part of a free
    00022 // software library without restriction.  Specifically, if other files
    00023 // instantiate templates or use macros or inline functions from this
    00024 // file, or you compile this file and link it with other files to
    00025 // produce an executable, this file does not by itself cause the
    00026 // resulting executable to be covered by the GNU General Public
    00027 // License.  This exception does not however invalidate any other
    00028 // reasons why the executable file might be covered by the GNU General
    00029 // Public License.
    00030
    00031 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
    00032
    00033 // Permission to use, copy, modify, sell, and distribute this software
    00034 // is hereby granted without fee, provided that the above copyright
    00035 // notice appears in all copies, and that both that copyright notice
    00036 // and this permission notice appear in supporting documentation. None
    00037 // of the above authors, nor IBM Haifa Research Laboratories, make any
    00038 // representation about the suitability of this software for any
    00039 // purpose. It is provided "as is" without express or implied
    00040 // warranty.
    00041
    00042 /**
    00043  * @file standard_policies.hpp
    00044  * Contains standard policies for containers.
    00045  */
    00046
    00047 #ifndef PB_DS_STANDARD_POLICIES_HPP
    00048 #define PB_DS_STANDARD_POLICIES_HPP
    00049
    00050 #include <memory>
    00051 #include <ext/pb_ds/hash_policy.hpp>
    00052 #include <ext/pb_ds/list_update_policy.hpp>
    00053 #include <ext/pb_ds/tree_policy.hpp>
    00054 #include <ext/pb_ds/detail/basic_tree_policy/null_node_metadata.hpp>
    00055 #include <ext/pb_ds/trie_policy.hpp>
    00056 #include <ext/pb_ds/tag_and_trait.hpp>
    00057 #include <tr1/functional>
    00058
    00059 namespace __gnu_pbds
    00060 {
    00061   namespace detail
    00062   {
    00063     template<typename Key>
    00064     struct default_hash_fn
    00065     {
    00066       typedef std::tr1::hash<Key> type;
    00067     };
    00068
    00069     template<typename Key>
    00070     struct default_eq_fn
    00071     {
    00072       typedef std::equal_to<Key> type;
    00073     };
    00074
    00075     enum
    00076       {
    00077     default_store_hash = false
    00078       };
    00079
    00080     struct default_comb_hash_fn
    00081     {
    00082       typedef __gnu_pbds::direct_mask_range_hashing<> type;
    00083     };
    00084
    00085     template<typename Comb_Hash_Fn>
    00086     struct default_resize_policy
    00087     {
    00088     private:
    00089       typedef typename Comb_Hash_Fn::size_type size_type;
    00090
    00091       typedef __gnu_pbds::direct_mask_range_hashing<size_type> default_fn;
    00092       typedef is_same<default_fn, Comb_Hash_Fn> same_type;
    00093       typedef __gnu_pbds::hash_exponential_size_policy<size_type> iftrue;
    00094       typedef __gnu_pbds::hash_prime_size_policy iffalse;
    00095       typedef __conditional_type<same_type::value, iftrue, iffalse> cond_type;
    00096       typedef typename cond_type::__type size_policy_type;
    00097
    00098       typedef __gnu_pbds::hash_load_check_resize_trigger<false, size_type> trigger;
    00099
    00100     public:
    00101       typedef __gnu_pbds::hash_standard_resize_policy<size_policy_type, trigger, false, size_type> type;
    00102     };
    00103
    00104     struct default_update_policy
    00105     {
    00106       typedef __gnu_pbds::move_to_front_lu_policy<> type;
    00107     };
    00108
    00109     template<typename Comb_Probe_Fn>
    00110     struct default_probe_fn
    00111     {
    00112     private:
    00113       typedef typename Comb_Probe_Fn::size_type size_type;
    00114
    00115       typedef __gnu_pbds::direct_mask_range_hashing<size_type> default_fn;
    00116       typedef is_same<default_fn, Comb_Probe_Fn> same_type;
    00117       typedef __gnu_pbds::linear_probe_fn<size_type> iftrue;
    00118       typedef __gnu_pbds::quadratic_probe_fn<size_type> iffalse;
    00119       typedef __conditional_type<same_type::value, iftrue, iffalse> cond_type;
    00120
    00121     public:
    00122       typedef typename cond_type::__type type;
    00123     };
    00124
    00125     template<typename Key>
    00126     struct default_trie_e_access_traits;
    00127
    00128     template<typename Char, class Char_Traits>
    00129     struct default_trie_e_access_traits<std::basic_string<Char, Char_Traits, std::allocator<char> > >
    00130     {
    00131     private:
    00132       typedef std::basic_string<Char, Char_Traits, std::allocator<char> > string_type;
    00133
    00134     public:
    00135       typedef __gnu_pbds::string_trie_e_access_traits<string_type> type;
    00136     };
    00137
    00138   } // namespace detail
    00139 } // namespace __gnu_pbds
    00140
    00141 #endif // #ifndef PB_DS_STANDARD_POLICIES_HPP
    00142