From 8df282b2e614384fe97526e0535a5fc0efd4095b Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Tue, 9 Jul 2024 21:15:50 +0200 Subject: [PATCH] wip --- include/util/query_heap.hpp | 59 ++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/include/util/query_heap.hpp b/include/util/query_heap.hpp index e2d3ed4a9..83814a470 100644 --- a/include/util/query_heap.hpp +++ b/include/util/query_heap.hpp @@ -1,12 +1,13 @@ #ifndef OSRM_UTIL_QUERY_HEAP_HPP #define OSRM_UTIL_QUERY_HEAP_HPP +#include "util/pool_allocator.hpp" +#include #include #include - -#include #include #include +#include #include #include #include @@ -121,8 +122,6 @@ template class UnorderedMapStorage void Clear() { nodes.clear(); } private: - template using PoolAllocator = boost::fast_pool_allocator; - template using UnorderedMap = std:: unordered_map, std::equal_to, PoolAllocator>>; @@ -191,6 +190,53 @@ class TwoLevelStorage OverlayIndexStorage overlay; }; +template class LoggingAllocator +{ + public: + using value_type = T; + + LoggingAllocator() noexcept = default; + template LoggingAllocator(const LoggingAllocator &) noexcept {} + + T *allocate(std::size_t n) + { + if (n == 1024) + { + std::cerr << "bingo\n"; + } + + auto p = std::allocator().allocate(n); + if (n != 1) + { + std::cout << "Allocated " << n << " element(s) of size " << sizeof(T) << " at " + << static_cast(p) << std::endl; + } + + return p; + } + + void deallocate(T *p, std::size_t n) noexcept + { + // std::cout << "Deallocated " << n << " element(s) at " << static_cast(p) << + // std::endl; + std::allocator().deallocate(p, n); + } + + template void construct(U *p, Args &&...args) + { + std::allocator a; + // std::cout << "Constructing object at " << static_cast(p) << std::endl; + std::allocator_traits>::construct(a, p, std::forward(args)...); + } + + template void destroy(U *p) + { + // std::cout << "Destroying object at " << static_cast(p) << std::endl; + std::allocator a; + std::allocator_traits>::destroy(a, p); + } +}; + template other.weight; } }; - using HeapContainerAllocator = - std::allocator; // boost::fast_pool_allocator; using HeapContainer = boost::heap::d_ary_heap, boost::heap::mutable_, boost::heap::compare>, - boost::heap::allocator>; + boost::heap::allocator>>; using HeapHandle = typename HeapContainer::handle_type; public: @@ -244,6 +288,7 @@ class QueryHeap heap.clear(); inserted_nodes.clear(); node_index.Clear(); + heap.reserve(1024); } std::size_t Size() const { return heap.size(); }