From 4af8f8e3c8d25a82ccdcf806b0b02fb4273214c8 Mon Sep 17 00:00:00 2001 From: Nicolas Mellado Date: Mon, 19 Jul 2021 12:59:34 +0200 Subject: [PATCH] [core] Expose LayerKeyHash struct Allow to reuse layers hash function outside of MultiIndexedGeometry --- src/Core/Geometry/IndexedGeometry.cpp | 2 +- src/Core/Geometry/IndexedGeometry.hpp | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Core/Geometry/IndexedGeometry.cpp b/src/Core/Geometry/IndexedGeometry.cpp index 4eb367fa8fd..2a9868c8071 100644 --- a/src/Core/Geometry/IndexedGeometry.cpp +++ b/src/Core/Geometry/IndexedGeometry.cpp @@ -252,7 +252,7 @@ void MultiIndexedGeometry::deepClear() { ////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// -std::size_t MultiIndexedGeometry::KeyHash::operator()( const LayerKeyType& k ) const { +std::size_t MultiIndexedGeometry::LayerKeyHash::operator()( const LayerKeyType& k ) const { // Mix semantic collection into a single identifier string std::ostringstream stream; std::copy( k.first.begin(), k.first.end(), std::ostream_iterator( stream, "" ) ); diff --git a/src/Core/Geometry/IndexedGeometry.hpp b/src/Core/Geometry/IndexedGeometry.hpp index fccf0c8cef3..6cda1aea48f 100644 --- a/src/Core/Geometry/IndexedGeometry.hpp +++ b/src/Core/Geometry/IndexedGeometry.hpp @@ -373,17 +373,21 @@ class RA_CORE_API MultiIndexedGeometry : public AttribArrayGeometry, public Util /// Note: we cannot store unique_ptr here has unordered_map needs its /// elements to be copy-constructible - using EntryType = std::pair; - struct RA_CORE_API KeyHash { + using LayerEntryType = std::pair; + + public: + /// Hash function for layer keys + struct RA_CORE_API LayerKeyHash { std::size_t operator()( const LayerKeyType& k ) const; }; + private: /// Collection of pairs /// \note There is no natural ordering for these elements, thus /// we need an unordered_map. In contrast to map, transparent hashing /// require c++20, so we need to implement them explicitely here /// https://en.cppreference.com/w/cpp/container/unordered_map/find - std::unordered_map m_indices; + std::unordered_map m_indices; }; struct RA_CORE_API PointCloudIndexLayer : public GeometryIndexLayer {