Commit 3cd110c7 authored by Illia Kolesnik's avatar Illia Kolesnik
Browse files

Performance improvements for LinearOctree

parent e416b9fb
Loading
Loading
Loading
Loading
+38 −8
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ private:
#endif

   StaticArray< 27, StaticArray< 8, std::pair< PosCodes, Direction > > > m_NeighbourTable;
   StaticArray< 8, uint8_t > m_PosCodeToOrderConversion;  // convert PosCodes to insert order

   /* ----------------- Private Methods ------------------- */

@@ -58,6 +59,25 @@ private:
      return m_NeighbourTable[ d.getTableIndex() ][ p ];
   }

   constexpr Index
   convertPosCodeToOrder( const PosCodes& p ) const
   {
      return m_PosCodeToOrderConversion[ static_cast< uint8_t >( p ) ];
   }

   constexpr void
   fillPosCodeToOrderConversion()
   {
      m_PosCodeToOrderConversion[ static_cast< uint8_t >( PosCodes::LUB ) ] = Direction::getInsertOrder( Direction::LUB );
      m_PosCodeToOrderConversion[ static_cast< uint8_t >( PosCodes::RUB ) ] = Direction::getInsertOrder( Direction::RUB );
      m_PosCodeToOrderConversion[ static_cast< uint8_t >( PosCodes::RUF ) ] = Direction::getInsertOrder( Direction::RUF );
      m_PosCodeToOrderConversion[ static_cast< uint8_t >( PosCodes::LUF ) ] = Direction::getInsertOrder( Direction::LUF );
      m_PosCodeToOrderConversion[ static_cast< uint8_t >( PosCodes::LDB ) ] = Direction::getInsertOrder( Direction::LDB );
      m_PosCodeToOrderConversion[ static_cast< uint8_t >( PosCodes::RDB ) ] = Direction::getInsertOrder( Direction::RDB );
      m_PosCodeToOrderConversion[ static_cast< uint8_t >( PosCodes::RDF ) ] = Direction::getInsertOrder( Direction::RDF );
      m_PosCodeToOrderConversion[ static_cast< uint8_t >( PosCodes::LDF ) ] = Direction::getInsertOrder( Direction::LDF );
   }

   constexpr void
   fillExtendedTable( const Direction& directionToFill )
   {
@@ -162,6 +182,8 @@ private:
      fillExtendedTable( Direction::RDF );
      fillExtendedTable( Direction::DF );
      fillExtendedTable( Direction::LDF );

      fillPosCodeToOrderConversion();
   }

   void
@@ -268,10 +290,9 @@ public:

      const Index firstChildrenId = m_Cells.size();
      /* Set other parameters */
      for( Index i = 0; i < 8; i++ ) {
         /* Add location code to hash map */
         insertIndex( children[ i ].locCode, firstChildrenId + i );
      }

      /* Add to hash map start of block only */
      insertIndex( children[ 0 ].locCode, firstChildrenId );

      cellToRefine.setRefined();
      /* Append all children to cells */
@@ -402,11 +423,19 @@ public:
   [[nodiscard]] Index
   getIndex( const LocCode& locCode ) const
   {
      /* Check if empty to prevent clearing delimiter bit */
      if( locCode.isEmpty() )
         return 0;

      const PosCodes lastCode = locCode.getLastCode();
      const LocCode newLocCode = locCode.setCodeAtPos( 0, PosCodes::LUB );  // Should be first inserted
      Index result = 0;
#ifdef HAVE_CUCKOO
      return findIndex( locCode ).value();
      result = findIndex( newLocCode ).value();
#else
      return m_CellMap.at( locCode.getCode() );
      result = m_CellMap.at( newLocCode.getCode() );
#endif
      return result + convertPosCodeToOrder( lastCode );
   }

   void
@@ -422,10 +451,11 @@ public:
   [[nodiscard]] bool
   checkIndex( const LocCode& locCode ) const
   {
      const LocCode newLocCode = locCode.setCodeAtPos( 0, PosCodes::LUB );  // Should be first inserted
#ifdef HAVE_CUCKOO
      return m_CellMap.contains( locCode.getCode() );
      return m_CellMap.contains( newLocCode.getCode() );
#else
      return m_CellMap.contains( locCode.getCode() );
      return m_CellMap.contains( newLocCode.getCode() );
#endif
   }

+6 −0
Original line number Diff line number Diff line
@@ -86,6 +86,12 @@ public:
      return static_cast< PosCodes >( loc & 0b111 );
   }

   constexpr PosCodes
   getLastCode() const
   {
      return static_cast< PosCodes >( m_Code & 0b111 );
   }

   constexpr LocCode
   setCodeAtPos( int pos, PosCodes code ) const
   {