1
1
#ifndef OSRM_UTIL_QUERY_HEAP_HPP
2
2
#define OSRM_UTIL_QUERY_HEAP_HPP
3
3
4
+ #include " util/pool_allocator.hpp"
5
+ #include < algorithm>
4
6
#include < boost/assert.hpp>
5
7
#include < boost/heap/d_ary_heap.hpp>
6
-
7
- #include < algorithm>
8
8
#include < boost/pool/pool_alloc.hpp>
9
9
#include < cstdint>
10
+ #include < iostream>
10
11
#include < limits>
11
12
#include < map>
12
13
#include < optional>
@@ -121,8 +122,6 @@ template <typename NodeID, typename Key> class UnorderedMapStorage
121
122
void Clear () { nodes.clear (); }
122
123
123
124
private:
124
- template <typename T> using PoolAllocator = boost::fast_pool_allocator<T>;
125
-
126
125
template <typename K, typename V>
127
126
using UnorderedMap = std::
128
127
unordered_map<K, V, std::hash<K>, std::equal_to<K>, PoolAllocator<std::pair<const K, V>>>;
@@ -191,6 +190,53 @@ class TwoLevelStorage
191
190
OverlayIndexStorage<NodeID, Key> overlay;
192
191
};
193
192
193
+ template <typename T> class LoggingAllocator
194
+ {
195
+ public:
196
+ using value_type = T;
197
+
198
+ LoggingAllocator () noexcept = default ;
199
+ template <typename U> LoggingAllocator (const LoggingAllocator<U> &) noexcept {}
200
+
201
+ T *allocate (std::size_t n)
202
+ {
203
+ if (n == 1024 )
204
+ {
205
+ std::cerr << " bingo\n " ;
206
+ }
207
+
208
+ auto p = std::allocator<T>().allocate (n);
209
+ if (n != 1 )
210
+ {
211
+ std::cout << " Allocated " << n << " element(s) of size " << sizeof (T) << " at "
212
+ << static_cast <void *>(p) << std::endl;
213
+ }
214
+
215
+ return p;
216
+ }
217
+
218
+ void deallocate (T *p, std::size_t n) noexcept
219
+ {
220
+ // std::cout << "Deallocated " << n << " element(s) at " << static_cast<void*>(p) <<
221
+ // std::endl;
222
+ std::allocator<T>().deallocate (p, n);
223
+ }
224
+
225
+ template <typename U, typename ... Args> void construct (U *p, Args &&...args)
226
+ {
227
+ std::allocator<T> a;
228
+ // std::cout << "Constructing object at " << static_cast<void*>(p) << std::endl;
229
+ std::allocator_traits<std::allocator<T>>::construct (a, p, std::forward<Args>(args)...);
230
+ }
231
+
232
+ template <typename U> void destroy (U *p)
233
+ {
234
+ // std::cout << "Destroying object at " << static_cast<void*>(p) << std::endl;
235
+ std::allocator<T> a;
236
+ std::allocator_traits<std::allocator<T>>::destroy (a, p);
237
+ }
238
+ };
239
+
194
240
template <typename NodeID,
195
241
typename Key,
196
242
typename Weight,
@@ -213,13 +259,11 @@ class QueryHeap
213
259
return weight > other.weight ;
214
260
}
215
261
};
216
- using HeapContainerAllocator =
217
- std::allocator<HeapData>; // boost::fast_pool_allocator<HeapData>;
218
262
using HeapContainer = boost::heap::d_ary_heap<HeapData,
219
263
boost::heap::arity<4 >,
220
264
boost::heap::mutable_<true >,
221
265
boost::heap::compare<std::greater<HeapData>>,
222
- boost::heap::allocator<HeapContainerAllocator >>;
266
+ boost::heap::allocator<PoolAllocator<HeapData> >>;
223
267
using HeapHandle = typename HeapContainer::handle_type;
224
268
225
269
public:
@@ -244,6 +288,7 @@ class QueryHeap
244
288
heap.clear ();
245
289
inserted_nodes.clear ();
246
290
node_index.Clear ();
291
+ heap.reserve (1024 );
247
292
}
248
293
249
294
std::size_t Size () const { return heap.size (); }
0 commit comments