Skip to content

Commit

Permalink
[core] Expose LayerKeyHash struct
Browse files Browse the repository at this point in the history
Allow to reuse layers hash function outside of MultiIndexedGeometry
  • Loading branch information
nmellado committed Jul 19, 2021
1 parent e22754d commit 4af8f8e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Core/Geometry/IndexedGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>( stream, "" ) );
Expand Down
10 changes: 7 additions & 3 deletions src/Core/Geometry/IndexedGeometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool, GeometryIndexLayerBase*>;
struct RA_CORE_API KeyHash {
using LayerEntryType = std::pair<bool, GeometryIndexLayerBase*>;

public:
/// Hash function for layer keys
struct RA_CORE_API LayerKeyHash {
std::size_t operator()( const LayerKeyType& k ) const;
};

private:
/// Collection of pairs <lockStatus, Indices>
/// \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<LayerKeyType, EntryType, KeyHash> m_indices;
std::unordered_map<LayerKeyType, LayerEntryType, LayerKeyHash> m_indices;
};

struct RA_CORE_API PointCloudIndexLayer : public GeometryIndexLayer<Vector1ui> {
Expand Down

0 comments on commit 4af8f8e

Please sign in to comment.