Chris@16
|
1 // boost heap
|
Chris@16
|
2 //
|
Chris@16
|
3 // Copyright (C) 2010-2011 Tim Blechmann
|
Chris@16
|
4 //
|
Chris@16
|
5 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@16
|
6 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
7 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8
|
Chris@16
|
9 #ifndef BOOST_HEAP_POLICIES_HPP
|
Chris@16
|
10 #define BOOST_HEAP_POLICIES_HPP
|
Chris@16
|
11
|
Chris@16
|
12 #include <boost/parameter.hpp>
|
Chris@16
|
13 #include <boost/mpl/bool.hpp>
|
Chris@16
|
14 #include <boost/mpl/int.hpp>
|
Chris@16
|
15 #include <boost/mpl/void.hpp>
|
Chris@16
|
16 #include <boost/concept_check.hpp>
|
Chris@16
|
17
|
Chris@16
|
18
|
Chris@16
|
19 namespace boost {
|
Chris@16
|
20 namespace heap {
|
Chris@16
|
21
|
Chris@16
|
22 #ifndef BOOST_DOXYGEN_INVOKED
|
Chris@16
|
23 BOOST_PARAMETER_TEMPLATE_KEYWORD(allocator)
|
Chris@16
|
24 BOOST_PARAMETER_TEMPLATE_KEYWORD(compare)
|
Chris@16
|
25
|
Chris@16
|
26 namespace tag { struct stable; }
|
Chris@16
|
27
|
Chris@16
|
28 template <bool T>
|
Chris@16
|
29 struct stable:
|
Chris@16
|
30 boost::parameter::template_keyword<tag::stable, boost::mpl::bool_<T> >
|
Chris@16
|
31 {};
|
Chris@16
|
32
|
Chris@16
|
33 namespace tag { struct mutable_; }
|
Chris@16
|
34
|
Chris@16
|
35 template <bool T>
|
Chris@16
|
36 struct mutable_:
|
Chris@16
|
37 boost::parameter::template_keyword<tag::mutable_, boost::mpl::bool_<T> >
|
Chris@16
|
38 {};
|
Chris@16
|
39
|
Chris@16
|
40
|
Chris@16
|
41 namespace tag { struct constant_time_size; }
|
Chris@16
|
42
|
Chris@16
|
43 template <bool T>
|
Chris@16
|
44 struct constant_time_size:
|
Chris@16
|
45 boost::parameter::template_keyword<tag::constant_time_size, boost::mpl::bool_<T> >
|
Chris@16
|
46 {};
|
Chris@16
|
47
|
Chris@16
|
48 namespace tag { struct store_parent_pointer; }
|
Chris@16
|
49
|
Chris@16
|
50 template <bool T>
|
Chris@16
|
51 struct store_parent_pointer:
|
Chris@16
|
52 boost::parameter::template_keyword<tag::store_parent_pointer, boost::mpl::bool_<T> >
|
Chris@16
|
53 {};
|
Chris@16
|
54
|
Chris@16
|
55 namespace tag { struct arity; }
|
Chris@16
|
56
|
Chris@16
|
57 template <unsigned int T>
|
Chris@16
|
58 struct arity:
|
Chris@16
|
59 boost::parameter::template_keyword<tag::arity, boost::mpl::int_<T> >
|
Chris@16
|
60 {};
|
Chris@16
|
61
|
Chris@16
|
62 namespace tag { struct objects_per_page; }
|
Chris@16
|
63
|
Chris@16
|
64 template <unsigned int T>
|
Chris@16
|
65 struct objects_per_page:
|
Chris@16
|
66 boost::parameter::template_keyword<tag::objects_per_page, boost::mpl::int_<T> >
|
Chris@16
|
67 {};
|
Chris@16
|
68
|
Chris@16
|
69 BOOST_PARAMETER_TEMPLATE_KEYWORD(stability_counter_type)
|
Chris@16
|
70
|
Chris@16
|
71 namespace detail {
|
Chris@16
|
72
|
Chris@16
|
73 namespace mpl = boost::mpl;
|
Chris@16
|
74
|
Chris@16
|
75 template <typename bound_args, typename tag_type>
|
Chris@16
|
76 struct has_arg
|
Chris@16
|
77 {
|
Chris@16
|
78 typedef typename boost::parameter::binding<bound_args, tag_type, mpl::void_>::type type;
|
Chris@16
|
79 static const bool value = mpl::is_not_void_<type>::type::value;
|
Chris@16
|
80 };
|
Chris@16
|
81
|
Chris@16
|
82 template <typename bound_args>
|
Chris@16
|
83 struct extract_stable
|
Chris@16
|
84 {
|
Chris@16
|
85 static const bool has_stable = has_arg<bound_args, tag::stable>::value;
|
Chris@16
|
86
|
Chris@16
|
87 typedef typename mpl::if_c<has_stable,
|
Chris@16
|
88 typename has_arg<bound_args, tag::stable>::type,
|
Chris@16
|
89 mpl::bool_<false>
|
Chris@16
|
90 >::type stable_t;
|
Chris@16
|
91
|
Chris@16
|
92 static const bool value = stable_t::value;
|
Chris@16
|
93 };
|
Chris@16
|
94
|
Chris@16
|
95 template <typename bound_args>
|
Chris@16
|
96 struct extract_mutable
|
Chris@16
|
97 {
|
Chris@16
|
98 static const bool has_mutable = has_arg<bound_args, tag::mutable_>::value;
|
Chris@16
|
99
|
Chris@16
|
100 typedef typename mpl::if_c<has_mutable,
|
Chris@16
|
101 typename has_arg<bound_args, tag::mutable_>::type,
|
Chris@16
|
102 mpl::bool_<false>
|
Chris@16
|
103 >::type mutable_t;
|
Chris@16
|
104
|
Chris@16
|
105 static const bool value = mutable_t::value;
|
Chris@16
|
106 };
|
Chris@16
|
107
|
Chris@16
|
108 }
|
Chris@16
|
109
|
Chris@16
|
110 #else
|
Chris@16
|
111
|
Chris@16
|
112 /** \brief Specifies the predicate for the heap order
|
Chris@16
|
113 */
|
Chris@16
|
114 template <typename T>
|
Chris@16
|
115 struct compare{};
|
Chris@16
|
116
|
Chris@16
|
117 /** \brief Configure heap as mutable
|
Chris@16
|
118 *
|
Chris@16
|
119 * Certain heaps need to be configured specifically do be mutable.
|
Chris@16
|
120 *
|
Chris@16
|
121 * */
|
Chris@16
|
122 template <bool T>
|
Chris@16
|
123 struct mutable_{};
|
Chris@16
|
124
|
Chris@16
|
125 /** \brief Specifies allocator for the internal memory management
|
Chris@16
|
126 */
|
Chris@16
|
127 template <typename T>
|
Chris@16
|
128 struct allocator{};
|
Chris@16
|
129
|
Chris@16
|
130 /** \brief Configure a heap as \b stable
|
Chris@16
|
131 *
|
Chris@16
|
132 * A priority queue is stable, if elements with the same priority are popped from the heap, in the same order as
|
Chris@16
|
133 * they are inserted.
|
Chris@16
|
134 * */
|
Chris@16
|
135 template <bool T>
|
Chris@16
|
136 struct stable{};
|
Chris@16
|
137
|
Chris@16
|
138 /** \brief Specifies the type for stability counter
|
Chris@16
|
139 *
|
Chris@16
|
140 * */
|
Chris@16
|
141 template <typename IntType>
|
Chris@16
|
142 struct stability_counter_type{};
|
Chris@16
|
143
|
Chris@16
|
144 /** \brief Configures complexity of <tt> size() </tt>
|
Chris@16
|
145 *
|
Chris@16
|
146 * Specifies, whether size() should have linear or constant complexity.
|
Chris@16
|
147 * */
|
Chris@16
|
148 template <bool T>
|
Chris@16
|
149 struct constant_time_size{};
|
Chris@16
|
150
|
Chris@16
|
151 /** \brief Store parent pointer in heap node.
|
Chris@16
|
152 *
|
Chris@16
|
153 * Maintaining a parent pointer adds some maintenance and size overhead, but iterating a heap is more efficient.
|
Chris@16
|
154 * */
|
Chris@16
|
155 template <bool T>
|
Chris@16
|
156 struct store_parent_pointer{};
|
Chris@16
|
157
|
Chris@16
|
158 /** \brief Specify arity.
|
Chris@16
|
159 *
|
Chris@16
|
160 * Specifies the arity of a D-ary heap
|
Chris@16
|
161 * */
|
Chris@16
|
162 template <unsigned int T>
|
Chris@16
|
163 struct arity{};
|
Chris@16
|
164 #endif
|
Chris@16
|
165
|
Chris@16
|
166 } /* namespace heap */
|
Chris@16
|
167 } /* namespace boost */
|
Chris@16
|
168
|
Chris@16
|
169 #endif /* BOOST_HEAP_POLICIES_HPP */
|