DGtal 2.0.0
Loading...
Searching...
No Matches
DynArrayXYOfLabelledMap< Value, L, TWord, N, M > Class Template Reference

Public Types

typedef Value ValueType

Public Member Functions

 DynArrayXYOfLabelledMap (unsigned int _X, unsigned int _Y)
 ~DynArrayXYOfLabelledMap ()
size_t offset (unsigned int x, unsigned int y) const
void clear ()
const Valuevalue (unsigned int l, unsigned int x, unsigned int y) const
void setValue (const Value &val, unsigned int l, unsigned int x, unsigned int y)
unsigned int erase (unsigned int l, unsigned int x, unsigned int y)
void setValueNoNewLabel (const Value &val, unsigned int l, unsigned int x, unsigned int y)
bool hasLabel (unsigned int l, unsigned int x, unsigned int y) const
void getLabels (std::vector< unsigned int > &labels, unsigned int x, unsigned int y) const
unsigned int nbLabels (unsigned int x, unsigned int y) const
void display (ostream &, unsigned int, unsigned int x, unsigned int y)
unsigned long long area () const

Data Fields

const unsigned int X
const unsigned int Y

Private Types

typedef LabelledMap< Value, L, TWord, N, M > MyLabelledMap

Private Attributes

MyLabelledMap_data

Detailed Description

template<typename Value, unsigned int L, typename TWord, unsigned int N, unsigned int M>
class DynArrayXYOfLabelledMap< Value, L, TWord, N, M >

Array[X][Y] of LabelledMap<L>

The proposed alternative to the brute-force approach. Generally less than 10 times the memory used by brute force for L >= 16. Approximately 50% slower in most operations, except initialization or used of all labels. In this case outperforms Array[L][X][Y].

Note that 4000*4000*16 is fine on my 8Gb laptop (529Mb). Note that 2000*2000*64 takes 133Mb.

Definition at line 478 of file testMultiMap-benchmark.cpp.

Member Typedef Documentation

◆ MyLabelledMap

template<typename Value, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef LabelledMap< Value, L, TWord, N, M> DynArrayXYOfLabelledMap< Value, L, TWord, N, M >::MyLabelledMap
private

Definition at line 479 of file testMultiMap-benchmark.cpp.

◆ ValueType

template<typename Value, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef Value DynArrayXYOfLabelledMap< Value, L, TWord, N, M >::ValueType

Definition at line 481 of file testMultiMap-benchmark.cpp.

Constructor & Destructor Documentation

◆ DynArrayXYOfLabelledMap()

template<typename Value, unsigned int L, typename TWord, unsigned int N, unsigned int M>
DynArrayXYOfLabelledMap< Value, L, TWord, N, M >::DynArrayXYOfLabelledMap ( unsigned int _X,
unsigned int _Y )
inline

Definition at line 490 of file testMultiMap-benchmark.cpp.

491 : X( _X ), Y( _Y )
492 {
493 _data = new MyLabelledMap[ X * Y ];
494 }
LabelledMap< Value, L, TWord, N, M > MyLabelledMap

References _data, X, and Y.

◆ ~DynArrayXYOfLabelledMap()

template<typename Value, unsigned int L, typename TWord, unsigned int N, unsigned int M>
DynArrayXYOfLabelledMap< Value, L, TWord, N, M >::~DynArrayXYOfLabelledMap ( )
inline

Definition at line 496 of file testMultiMap-benchmark.cpp.

497 {
498 delete[] _data;
499 }

References _data.

Member Function Documentation

◆ area()

template<typename Value, unsigned int L, typename TWord, unsigned int N, unsigned int M>
unsigned long long DynArrayXYOfLabelledMap< Value, L, TWord, N, M >::area ( ) const
inline

Definition at line 562 of file testMultiMap-benchmark.cpp.

563 {
564 unsigned long long total = 0;
565 for ( unsigned int y = 0; y < Y; ++y )
566 for ( unsigned int x = 0; x < X; ++x )
567 {
568 unsigned int size = nbLabels( x, y );
569 total += sizeof( MyLabelledMap );
570 if ( size > (N+1) )
571 total += ( 1 + ( size - N - 1 ) / M ) * ( M * sizeof( Value ) + 8 );
572 }
573 return total;
574 }
unsigned int nbLabels(unsigned int x, unsigned int y) const

References nbLabels(), X, and Y.

◆ clear()

template<typename Value, unsigned int L, typename TWord, unsigned int N, unsigned int M>
void DynArrayXYOfLabelledMap< Value, L, TWord, N, M >::clear ( )
inline

Definition at line 507 of file testMultiMap-benchmark.cpp.

508 {
509 for ( unsigned int y = 0; y < Y; ++y )
510 for ( unsigned int x = 0; x < X; ++x )
511 _data[ offset( x, y ) ].clear();
512 }
size_t offset(unsigned int x, unsigned int y) const

References _data, offset(), X, and Y.

◆ display()

template<typename Value, unsigned int L, typename TWord, unsigned int N, unsigned int M>
void DynArrayXYOfLabelledMap< Value, L, TWord, N, M >::display ( ostream & ,
unsigned int ,
unsigned int x,
unsigned int y )
inline

Definition at line 556 of file testMultiMap-benchmark.cpp.

557 {
558 std::cerr << _data[ offset( x, y ) ] << endl;
559 }

References _data, and offset().

◆ erase()

template<typename Value, unsigned int L, typename TWord, unsigned int N, unsigned int M>
unsigned int DynArrayXYOfLabelledMap< Value, L, TWord, N, M >::erase ( unsigned int l,
unsigned int x,
unsigned int y )
inline

Definition at line 527 of file testMultiMap-benchmark.cpp.

528 {
529 return _data[ offset( x, y ) ].erase( l );
530 }

References _data, and offset().

◆ getLabels()

template<typename Value, unsigned int L, typename TWord, unsigned int N, unsigned int M>
void DynArrayXYOfLabelledMap< Value, L, TWord, N, M >::getLabels ( std::vector< unsigned int > & labels,
unsigned int x,
unsigned int y ) const
inline

Definition at line 545 of file testMultiMap-benchmark.cpp.

547 {
548 _data[ offset( x, y ) ].labels().getLabels( labels );
549 }

References _data, and offset().

◆ hasLabel()

template<typename Value, unsigned int L, typename TWord, unsigned int N, unsigned int M>
bool DynArrayXYOfLabelledMap< Value, L, TWord, N, M >::hasLabel ( unsigned int l,
unsigned int x,
unsigned int y ) const
inline

Definition at line 539 of file testMultiMap-benchmark.cpp.

540 {
541 return _data[ offset( x, y ) ].count( l );
542 }

References _data, and offset().

◆ nbLabels()

template<typename Value, unsigned int L, typename TWord, unsigned int N, unsigned int M>
unsigned int DynArrayXYOfLabelledMap< Value, L, TWord, N, M >::nbLabels ( unsigned int x,
unsigned int y ) const
inline

Definition at line 552 of file testMultiMap-benchmark.cpp.

553 {
554 return static_cast<unsigned int>(_data[ offset( x, y ) ].size());
555 }

References _data, and offset().

Referenced by area().

◆ offset()

template<typename Value, unsigned int L, typename TWord, unsigned int N, unsigned int M>
size_t DynArrayXYOfLabelledMap< Value, L, TWord, N, M >::offset ( unsigned int x,
unsigned int y ) const
inline

Definition at line 501 of file testMultiMap-benchmark.cpp.

502 {
503 return x * Y + y;
504 }

References Y.

Referenced by clear(), display(), erase(), getLabels(), hasLabel(), nbLabels(), setValue(), setValueNoNewLabel(), and value().

◆ setValue()

template<typename Value, unsigned int L, typename TWord, unsigned int N, unsigned int M>
void DynArrayXYOfLabelledMap< Value, L, TWord, N, M >::setValue ( const Value & val,
unsigned int l,
unsigned int x,
unsigned int y )
inline

Definition at line 521 of file testMultiMap-benchmark.cpp.

522 {
523 _data[ offset( x, y ) ][ l ] = val;
524 }

References _data, and offset().

◆ setValueNoNewLabel()

template<typename Value, unsigned int L, typename TWord, unsigned int N, unsigned int M>
void DynArrayXYOfLabelledMap< Value, L, TWord, N, M >::setValueNoNewLabel ( const Value & val,
unsigned int l,
unsigned int x,
unsigned int y )
inline

Definition at line 533 of file testMultiMap-benchmark.cpp.

534 {
535 _data[ offset( x, y ) ].fastAt( l ) = val;
536 }

References _data, and offset().

◆ value()

template<typename Value, unsigned int L, typename TWord, unsigned int N, unsigned int M>
const Value & DynArrayXYOfLabelledMap< Value, L, TWord, N, M >::value ( unsigned int l,
unsigned int x,
unsigned int y ) const
inline

Definition at line 515 of file testMultiMap-benchmark.cpp.

516 {
517 return _data[ offset( x, y ) ].fastAt( l );
518 }

References _data, and offset().

Field Documentation

◆ _data

template<typename Value, unsigned int L, typename TWord, unsigned int N, unsigned int M>
MyLabelledMap* DynArrayXYOfLabelledMap< Value, L, TWord, N, M >::_data
private

◆ X

template<typename Value, unsigned int L, typename TWord, unsigned int N, unsigned int M>
const unsigned int DynArrayXYOfLabelledMap< Value, L, TWord, N, M >::X

Definition at line 482 of file testMultiMap-benchmark.cpp.

Referenced by area(), clear(), and DynArrayXYOfLabelledMap().

◆ Y

template<typename Value, unsigned int L, typename TWord, unsigned int N, unsigned int M>
const unsigned int DynArrayXYOfLabelledMap< Value, L, TWord, N, M >::Y

Definition at line 483 of file testMultiMap-benchmark.cpp.

Referenced by area(), clear(), DynArrayXYOfLabelledMap(), and offset().


The documentation for this class was generated from the following file: