xref: /dflybsd-src/contrib/gcc-4.7/libstdc++-v3/include/ext/pb_ds/detail/standard_policies.hpp (revision 04febcfb30580676d3e95f58a16c5137ee478b32)
1*e4b17023SJohn Marino // -*- C++ -*-
2*e4b17023SJohn Marino 
3*e4b17023SJohn Marino // Copyright (C) 2005, 2006, 2007, 2009, 2011 Free Software Foundation, Inc.
4*e4b17023SJohn Marino //
5*e4b17023SJohn Marino // This file is part of the GNU ISO C++ Library.  This library is free
6*e4b17023SJohn Marino // software; you can redistribute it and/or modify it under the terms
7*e4b17023SJohn Marino // of the GNU General Public License as published by the Free Software
8*e4b17023SJohn Marino // Foundation; either version 3, or (at your option) any later
9*e4b17023SJohn Marino // version.
10*e4b17023SJohn Marino 
11*e4b17023SJohn Marino // This library is distributed in the hope that it will be useful, but
12*e4b17023SJohn Marino // WITHOUT ANY WARRANTY; without even the implied warranty of
13*e4b17023SJohn Marino // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14*e4b17023SJohn Marino // General Public License for more details.
15*e4b17023SJohn Marino 
16*e4b17023SJohn Marino // Under Section 7 of GPL version 3, you are granted additional
17*e4b17023SJohn Marino // permissions described in the GCC Runtime Library Exception, version
18*e4b17023SJohn Marino // 3.1, as published by the Free Software Foundation.
19*e4b17023SJohn Marino 
20*e4b17023SJohn Marino // You should have received a copy of the GNU General Public License and
21*e4b17023SJohn Marino // a copy of the GCC Runtime Library Exception along with this program;
22*e4b17023SJohn Marino // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23*e4b17023SJohn Marino // <http://www.gnu.org/licenses/>.
24*e4b17023SJohn Marino 
25*e4b17023SJohn Marino // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
26*e4b17023SJohn Marino 
27*e4b17023SJohn Marino // Permission to use, copy, modify, sell, and distribute this software
28*e4b17023SJohn Marino // is hereby granted without fee, provided that the above copyright
29*e4b17023SJohn Marino // notice appears in all copies, and that both that copyright notice
30*e4b17023SJohn Marino // and this permission notice appear in supporting documentation. None
31*e4b17023SJohn Marino // of the above authors, nor IBM Haifa Research Laboratories, make any
32*e4b17023SJohn Marino // representation about the suitability of this software for any
33*e4b17023SJohn Marino // purpose. It is provided "as is" without express or implied
34*e4b17023SJohn Marino // warranty.
35*e4b17023SJohn Marino 
36*e4b17023SJohn Marino /**
37*e4b17023SJohn Marino  * @file detail/standard_policies.hpp
38*e4b17023SJohn Marino  * Contains standard policies for containers.
39*e4b17023SJohn Marino  */
40*e4b17023SJohn Marino 
41*e4b17023SJohn Marino #ifndef PB_DS_STANDARD_POLICIES_HPP
42*e4b17023SJohn Marino #define PB_DS_STANDARD_POLICIES_HPP
43*e4b17023SJohn Marino 
44*e4b17023SJohn Marino #include <memory>
45*e4b17023SJohn Marino #include <ext/pb_ds/hash_policy.hpp>
46*e4b17023SJohn Marino #include <ext/pb_ds/list_update_policy.hpp>
47*e4b17023SJohn Marino #include <ext/pb_ds/detail/branch_policy/null_node_metadata.hpp>
48*e4b17023SJohn Marino #include <ext/pb_ds/tree_policy.hpp>
49*e4b17023SJohn Marino #include <ext/pb_ds/trie_policy.hpp>
50*e4b17023SJohn Marino #include <ext/pb_ds/tag_and_trait.hpp>
51*e4b17023SJohn Marino #include <tr1/functional>
52*e4b17023SJohn Marino 
53*e4b17023SJohn Marino namespace __gnu_pbds
54*e4b17023SJohn Marino {
55*e4b17023SJohn Marino   namespace detail
56*e4b17023SJohn Marino   {
57*e4b17023SJohn Marino     /// Primary template, default_hash_fn.
58*e4b17023SJohn Marino     template<typename Key>
59*e4b17023SJohn Marino     struct default_hash_fn
60*e4b17023SJohn Marino     {
61*e4b17023SJohn Marino 	/// Dispatched type.
62*e4b17023SJohn Marino       typedef std::tr1::hash<Key> 				type;
63*e4b17023SJohn Marino     };
64*e4b17023SJohn Marino 
65*e4b17023SJohn Marino     /// Primary template, default_eq_fn.
66*e4b17023SJohn Marino     template<typename Key>
67*e4b17023SJohn Marino     struct default_eq_fn
68*e4b17023SJohn Marino     {
69*e4b17023SJohn Marino 	/// Dispatched type.
70*e4b17023SJohn Marino       typedef std::equal_to<Key> 				type;
71*e4b17023SJohn Marino     };
72*e4b17023SJohn Marino 
73*e4b17023SJohn Marino     /// Enumeration for default behavior of stored hash data.
74*e4b17023SJohn Marino     enum
75*e4b17023SJohn Marino       {
76*e4b17023SJohn Marino 	default_store_hash = false
77*e4b17023SJohn Marino       };
78*e4b17023SJohn Marino 
79*e4b17023SJohn Marino     /// Primary template, default_comb_hash_fn.
80*e4b17023SJohn Marino     struct default_comb_hash_fn
81*e4b17023SJohn Marino     {
82*e4b17023SJohn Marino 	/// Dispatched type.
83*e4b17023SJohn Marino       typedef direct_mask_range_hashing<> 			type;
84*e4b17023SJohn Marino     };
85*e4b17023SJohn Marino 
86*e4b17023SJohn Marino     /// Primary template, default_resize_policy.
87*e4b17023SJohn Marino     template<typename Comb_Hash_Fn>
88*e4b17023SJohn Marino     struct default_resize_policy
89*e4b17023SJohn Marino     {
90*e4b17023SJohn Marino     private:
91*e4b17023SJohn Marino       typedef typename Comb_Hash_Fn::size_type 			size_type;
92*e4b17023SJohn Marino 
93*e4b17023SJohn Marino       typedef direct_mask_range_hashing<size_type> 		default_fn;
94*e4b17023SJohn Marino       typedef is_same<default_fn, Comb_Hash_Fn> 		same_type;
95*e4b17023SJohn Marino       typedef hash_exponential_size_policy<size_type> 		iftrue;
96*e4b17023SJohn Marino       typedef hash_prime_size_policy 				iffalse;
97*e4b17023SJohn Marino       typedef __conditional_type<same_type::value, iftrue, iffalse> cond_type;
98*e4b17023SJohn Marino       typedef typename cond_type::__type 		       size_policy_type;
99*e4b17023SJohn Marino 
100*e4b17023SJohn Marino       typedef hash_load_check_resize_trigger<false, size_type> 	trigger;
101*e4b17023SJohn Marino 
102*e4b17023SJohn Marino     public:
103*e4b17023SJohn Marino 	/// Dispatched type.
104*e4b17023SJohn Marino       typedef hash_standard_resize_policy<size_policy_type, trigger,
105*e4b17023SJohn Marino 					  false, size_type> 	type;
106*e4b17023SJohn Marino     };
107*e4b17023SJohn Marino 
108*e4b17023SJohn Marino     /// Default update policy.
109*e4b17023SJohn Marino     struct default_update_policy
110*e4b17023SJohn Marino     {
111*e4b17023SJohn Marino 	/// Dispatched type.
112*e4b17023SJohn Marino       typedef lu_move_to_front_policy<> 			type;
113*e4b17023SJohn Marino     };
114*e4b17023SJohn Marino 
115*e4b17023SJohn Marino     /// Primary template, default_probe_fn.
116*e4b17023SJohn Marino     template<typename Comb_Probe_Fn>
117*e4b17023SJohn Marino     struct default_probe_fn
118*e4b17023SJohn Marino     {
119*e4b17023SJohn Marino     private:
120*e4b17023SJohn Marino       typedef typename Comb_Probe_Fn::size_type 		size_type;
121*e4b17023SJohn Marino       typedef direct_mask_range_hashing<size_type> 		default_fn;
122*e4b17023SJohn Marino       typedef is_same<default_fn, Comb_Probe_Fn> 		same_type;
123*e4b17023SJohn Marino       typedef linear_probe_fn<size_type> 			iftrue;
124*e4b17023SJohn Marino       typedef quadratic_probe_fn<size_type> 			iffalse;
125*e4b17023SJohn Marino       typedef __conditional_type<same_type::value, iftrue, iffalse> cond_type;
126*e4b17023SJohn Marino 
127*e4b17023SJohn Marino     public:
128*e4b17023SJohn Marino 	/// Dispatched type.
129*e4b17023SJohn Marino       typedef typename cond_type::__type 			type;
130*e4b17023SJohn Marino     };
131*e4b17023SJohn Marino 
132*e4b17023SJohn Marino 
133*e4b17023SJohn Marino     /// Primary template, default_trie_access_traits.
134*e4b17023SJohn Marino     template<typename Key>
135*e4b17023SJohn Marino       struct default_trie_access_traits;
136*e4b17023SJohn Marino 
137*e4b17023SJohn Marino #define __dtrie_alloc std::allocator<char>
138*e4b17023SJohn Marino #define __dtrie_string std::basic_string<Char, Char_Traits, __dtrie_alloc>
139*e4b17023SJohn Marino 
140*e4b17023SJohn Marino     /// Partial specialization, default_trie_access_traits.
141*e4b17023SJohn Marino     template<typename Char, typename Char_Traits>
142*e4b17023SJohn Marino       struct default_trie_access_traits<__dtrie_string>
143*e4b17023SJohn Marino       {
144*e4b17023SJohn Marino       private:
145*e4b17023SJohn Marino 	typedef __dtrie_string					string_type;
146*e4b17023SJohn Marino 
147*e4b17023SJohn Marino       public:
148*e4b17023SJohn Marino 	/// Dispatched type.
149*e4b17023SJohn Marino 	typedef trie_string_access_traits<string_type> 		type;
150*e4b17023SJohn Marino       };
151*e4b17023SJohn Marino 
152*e4b17023SJohn Marino #undef __dtrie_alloc
153*e4b17023SJohn Marino #undef __dtrie_string
154*e4b17023SJohn Marino 
155*e4b17023SJohn Marino   } // namespace detail
156*e4b17023SJohn Marino } // namespace __gnu_pbds
157*e4b17023SJohn Marino 
158*e4b17023SJohn Marino #endif // #ifndef PB_DS_STANDARD_POLICIES_HPP
159