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