DGtal 2.1.0
Loading...
Searching...
No Matches
ArrayXYOfList< Value, L, X, Y > Class Template Reference

Public Member Functions

 ArrayXYOfList ()
 
void clear ()
 
const Valuevalue (unsigned int l, unsigned int x, unsigned int y)
 
unsigned int erase (unsigned int l, unsigned int x, unsigned int y)
 
void setValue (const Value &val, 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, unsigned int)
 
unsigned long long area () const
 

Private Types

typedef std::pair< DGtal::uint16_t, ValueMyPair
 
typedef std::forward_list< MyPairMyList
 
typedef MyList::iterator Iterator
 
typedef MyList::const_iterator ConstIterator
 

Private Attributes

MyList _data [X][Y]
 

Detailed Description

template<typename Value, unsigned int L, unsigned int X, unsigned int Y>
class ArrayXYOfList< Value, L, X, Y >

Array[X][Y] of forward_list< pair<L,Value> > Another intermediate approach which favors less memory and more computation time.

Approximately same memory usage or 20% more as LabelledMap (for good values of N and M). Approximately 2 to 4 times slower than LabelledMap for most operations.

Note that 2000*2000*32 takes 216Mb.

Definition at line 256 of file testLabelledMap-benchmark.cpp.

Member Typedef Documentation

◆ ConstIterator

template<typename Value , unsigned int L, unsigned int X, unsigned int Y>
typedef MyList::const_iterator ArrayXYOfList< Value, L, X, Y >::ConstIterator
private

Definition at line 260 of file testLabelledMap-benchmark.cpp.

◆ Iterator

template<typename Value , unsigned int L, unsigned int X, unsigned int Y>
typedef MyList::iterator ArrayXYOfList< Value, L, X, Y >::Iterator
private

Definition at line 259 of file testLabelledMap-benchmark.cpp.

◆ MyList

template<typename Value , unsigned int L, unsigned int X, unsigned int Y>
typedef std::forward_list<MyPair> ArrayXYOfList< Value, L, X, Y >::MyList
private

Definition at line 258 of file testLabelledMap-benchmark.cpp.

◆ MyPair

template<typename Value , unsigned int L, unsigned int X, unsigned int Y>
typedef std::pair<DGtal::uint16_t, Value> ArrayXYOfList< Value, L, X, Y >::MyPair
private

Definition at line 257 of file testLabelledMap-benchmark.cpp.

Constructor & Destructor Documentation

◆ ArrayXYOfList()

template<typename Value , unsigned int L, unsigned int X, unsigned int Y>
ArrayXYOfList< Value, L, X, Y >::ArrayXYOfList ( )
inline

Definition at line 265 of file testLabelledMap-benchmark.cpp.

266 {
267 }

Member Function Documentation

◆ area()

template<typename Value , unsigned int L, unsigned int X, unsigned int Y>
unsigned long long ArrayXYOfList< Value, L, X, Y >::area ( ) const
inline

Definition at line 379 of file testLabelledMap-benchmark.cpp.

380 {
381 unsigned long long total = 0;
382 for ( unsigned int y = 0; y < Y; ++y )
383 for ( unsigned int x = 0; x < X; ++x )
384 {
385 unsigned int size = nbLabels( x, y );
386 total += sizeof( Value* )
387 + ( size ) *
388 ( sizeof( Value ) // one value per node
389 + sizeof( Value* ) // one pointers
390 + 2 // uint16_t
391 + 8 // dynamic allocation );
392 );
393 }
394 return total;
395 }
unsigned int nbLabels(unsigned int x, unsigned int y) const

References ArrayXYOfList< Value, L, X, Y >::nbLabels().

◆ clear()

template<typename Value , unsigned int L, unsigned int X, unsigned int Y>
void ArrayXYOfList< Value, L, X, Y >::clear ( )
inline

Definition at line 270 of file testLabelledMap-benchmark.cpp.

271 {
272 for ( unsigned int y = 0; y < Y; ++y )
273 for ( unsigned int x = 0; x < X; ++x )
274 _data[ x ][ y ].clear();
275 }

References ArrayXYOfList< Value, L, X, Y >::_data, and ArrayXYOfList< Value, L, X, Y >::clear().

Referenced by ArrayXYOfList< Value, L, X, Y >::clear().

◆ display()

template<typename Value , unsigned int L, unsigned int X, unsigned int Y>
void ArrayXYOfList< Value, L, X, Y >::display ( ostream &  ,
unsigned int  ,
unsigned int  ,
unsigned int   
)
inline

Definition at line 374 of file testLabelledMap-benchmark.cpp.

375 {}

◆ erase()

template<typename Value , unsigned int L, unsigned int X, unsigned int Y>
unsigned int ArrayXYOfList< Value, L, X, Y >::erase ( unsigned int  l,
unsigned int  x,
unsigned int  y 
)
inline

Definition at line 291 of file testLabelledMap-benchmark.cpp.

292 {
293 MyList & list = _data[ x ][ y ];
294 Iterator it_prev = list.before_begin();
295 Iterator it = list.begin(), it_end = list.end();
296 for ( ; it != it_end; ++it )
297 {
298 if ( it->first == l )
299 {
300 list.erase_after( it_prev );
301 return 1;
302 }
303 it_prev = it;
304 }
305 return 0;
306 }
std::forward_list< MyPair > MyList

References ArrayXYOfList< Value, L, X, Y >::_data.

◆ getLabels()

template<typename Value , unsigned int L, unsigned int X, unsigned int Y>
void ArrayXYOfList< Value, L, X, Y >::getLabels ( std::vector< unsigned int > &  labels,
unsigned int  x,
unsigned int  y 
) const
inline

Definition at line 352 of file testLabelledMap-benchmark.cpp.

354 {
355 labels.clear();
356 const MyList & list = _data[ x ][ y ];
357 ConstIterator it = list.begin(), it_end = list.end();
358 for ( ; it != it_end; ++it )
359 {
360 labels.push_back( (*it).first );
361 }
362 }
MyDigitalSurface::ConstIterator ConstIterator

References ArrayXYOfList< Value, L, X, Y >::_data.

◆ hasLabel()

template<typename Value , unsigned int L, unsigned int X, unsigned int Y>
bool ArrayXYOfList< Value, L, X, Y >::hasLabel ( unsigned int  l,
unsigned int  x,
unsigned int  y 
) const
inline

Definition at line 341 of file testLabelledMap-benchmark.cpp.

342 {
343 const MyList & list = _data[ x ][ y ];
344 ConstIterator it = list.begin(), it_end = list.end();
345 for ( ; it != it_end; ++it )
346 {
347 if ( it->first == l ) return true;
348 }
349 return false;
350 }

References ArrayXYOfList< Value, L, X, Y >::_data.

◆ nbLabels()

template<typename Value , unsigned int L, unsigned int X, unsigned int Y>
unsigned int ArrayXYOfList< Value, L, X, Y >::nbLabels ( unsigned int  x,
unsigned int  y 
) const
inline

Definition at line 364 of file testLabelledMap-benchmark.cpp.

365 {
366 const MyList & list = _data[ x ][ y ];
367 ConstIterator it = list.begin(), it_end = list.end();
368 unsigned int n = 0;
369 for ( ; it != it_end; ++it )
370 ++n;
371 return n;
372 }

References ArrayXYOfList< Value, L, X, Y >::_data.

Referenced by ArrayXYOfList< Value, L, X, Y >::area().

◆ setValue()

template<typename Value , unsigned int L, unsigned int X, unsigned int Y>
void ArrayXYOfList< Value, L, X, Y >::setValue ( const Value val,
unsigned int  l,
unsigned int  x,
unsigned int  y 
)
inline

Definition at line 309 of file testLabelledMap-benchmark.cpp.

310 {
311 MyList & list = _data[ x ][ y ];
312 Iterator it = list.begin(), it_end = list.end();
313 for ( ; it != it_end; ++it )
314 {
315 if ( it->first == l )
316 {
317 it->second = val;
318 return;
319 }
320 }
321 if ( it == it_end )
322 list.emplace_front( std::make_pair( l, val ) );
323 }

References ArrayXYOfList< Value, L, X, Y >::_data.

◆ setValueNoNewLabel()

template<typename Value , unsigned int L, unsigned int X, unsigned int Y>
void ArrayXYOfList< Value, L, X, Y >::setValueNoNewLabel ( const Value val,
unsigned int  l,
unsigned int  x,
unsigned int  y 
)
inline

Definition at line 325 of file testLabelledMap-benchmark.cpp.

326 {
327 MyList & list = _data[ x ][ y ];
328 Iterator it = list.begin(), it_end = list.end();
329 for ( ; it != it_end; ++it )
330 {
331 if ( it->first == l )
332 {
333 it->second = val;
334 return;
335 }
336 }
337 if ( it == it_end )
338 list.emplace_front( std::make_pair( l, val ) );
339 }

References ArrayXYOfList< Value, L, X, Y >::_data.

◆ value()

template<typename Value , unsigned int L, unsigned int X, unsigned int Y>
const Value & ArrayXYOfList< Value, L, X, Y >::value ( unsigned int  l,
unsigned int  x,
unsigned int  y 
)
inline

Definition at line 278 of file testLabelledMap-benchmark.cpp.

279 {
280 MyList & list = _data[ x ][ y ];
281 Iterator it = list.begin(), it_end = list.end();
282 for ( ; it != it_end; ++it )
283 {
284 if ( it->first == l ) return it->second;
285 }
286 ASSERT ( it == it_end ) ;
287 list.emplace_front( std::make_pair( l, Value() ) );
288 return list.front().second;
289 }

References ArrayXYOfList< Value, L, X, Y >::_data.

Field Documentation

◆ _data


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