Skip to content

Commit 8df282b

Browse files
wip
1 parent 5f166a5 commit 8df282b

File tree

1 file changed

+52
-7
lines changed

1 file changed

+52
-7
lines changed

include/util/query_heap.hpp

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#ifndef OSRM_UTIL_QUERY_HEAP_HPP
22
#define OSRM_UTIL_QUERY_HEAP_HPP
33

4+
#include "util/pool_allocator.hpp"
5+
#include <algorithm>
46
#include <boost/assert.hpp>
57
#include <boost/heap/d_ary_heap.hpp>
6-
7-
#include <algorithm>
88
#include <boost/pool/pool_alloc.hpp>
99
#include <cstdint>
10+
#include <iostream>
1011
#include <limits>
1112
#include <map>
1213
#include <optional>
@@ -121,8 +122,6 @@ template <typename NodeID, typename Key> class UnorderedMapStorage
121122
void Clear() { nodes.clear(); }
122123

123124
private:
124-
template <typename T> using PoolAllocator = boost::fast_pool_allocator<T>;
125-
126125
template <typename K, typename V>
127126
using UnorderedMap = std::
128127
unordered_map<K, V, std::hash<K>, std::equal_to<K>, PoolAllocator<std::pair<const K, V>>>;
@@ -191,6 +190,53 @@ class TwoLevelStorage
191190
OverlayIndexStorage<NodeID, Key> overlay;
192191
};
193192

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+
194240
template <typename NodeID,
195241
typename Key,
196242
typename Weight,
@@ -213,13 +259,11 @@ class QueryHeap
213259
return weight > other.weight;
214260
}
215261
};
216-
using HeapContainerAllocator =
217-
std::allocator<HeapData>; // boost::fast_pool_allocator<HeapData>;
218262
using HeapContainer = boost::heap::d_ary_heap<HeapData,
219263
boost::heap::arity<4>,
220264
boost::heap::mutable_<true>,
221265
boost::heap::compare<std::greater<HeapData>>,
222-
boost::heap::allocator<HeapContainerAllocator>>;
266+
boost::heap::allocator<PoolAllocator<HeapData>>>;
223267
using HeapHandle = typename HeapContainer::handle_type;
224268

225269
public:
@@ -244,6 +288,7 @@ class QueryHeap
244288
heap.clear();
245289
inserted_nodes.clear();
246290
node_index.Clear();
291+
heap.reserve(1024);
247292
}
248293

249294
std::size_t Size() const { return heap.size(); }

0 commit comments

Comments
 (0)