DGtal 2.1.0
Loading...
Searching...
No Matches
DynArrayXYOfMap< Value > Class Template Reference

Public Types

typedef Value ValueType
 

Public Member Functions

 DynArrayXYOfMap (unsigned int _L, unsigned int _X, unsigned int _Y)
 
 ~DynArrayXYOfMap ()
 
size_t offset (unsigned int x, unsigned int y) const
 
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
 

Data Fields

const unsigned int L
 
const unsigned int X
 
const unsigned int Y
 

Private Types

typedef std::map< unsigned int, ValueMyMap
 
typedef MyMap::const_iterator ConstIterator
 

Private Attributes

MyMap_data
 

Detailed Description

template<typename Value>
class DynArrayXYOfMap< Value >

Array[X][Y] of map<L,Value> Intermediate approach. Slower (between 30% and 40%) than ArrayXYOfLabelledMap and takes 50% to 100% twice as much place.

Note that 4000*4000*16 takes 861Mb. Note that 2000*2000*64 takes 218Mb.

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

Member Typedef Documentation

◆ ConstIterator

template<typename Value >
typedef MyMap::const_iterator DynArrayXYOfMap< Value >::ConstIterator
private

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

◆ MyMap

template<typename Value >
typedef std::map<unsigned int, Value> DynArrayXYOfMap< Value >::MyMap
private

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

◆ ValueType

template<typename Value >
typedef Value DynArrayXYOfMap< Value >::ValueType

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

Constructor & Destructor Documentation

◆ DynArrayXYOfMap()

template<typename Value >
DynArrayXYOfMap< Value >::DynArrayXYOfMap ( unsigned int  _L,
unsigned int  _X,
unsigned int  _Y 
)
inline

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

199 : L( _L ), X( _X ), Y( _Y )
200 {
201 _data = new MyMap[ X * Y ];
202 }
std::map< unsigned int, Value > MyMap

References DynArrayXYOfMap< Value >::_data, DynArrayXYOfMap< Value >::X, and DynArrayXYOfMap< Value >::Y.

◆ ~DynArrayXYOfMap()

template<typename Value >
DynArrayXYOfMap< Value >::~DynArrayXYOfMap ( )
inline

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

205 {
206 delete[] _data;
207 }

References DynArrayXYOfMap< Value >::_data.

Member Function Documentation

◆ area()

template<typename Value >
unsigned long long DynArrayXYOfMap< Value >::area ( ) const
inline

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

270 {
271 unsigned long long total = 0;
272 for ( unsigned int y = 0; y < Y; ++y )
273 for ( unsigned int x = 0; x < X; ++x )
274 {
275 unsigned int size = nbLabels( x, y );
276 total += ( size + 1 ) *
277 ( sizeof( Value ) // one value per node
278 + 3 * sizeof( Value* ) // three pointers
279 + 2 //_RbTreeColor { _S_red = false, _S_black = true };
280 + 8 // dynamic allocation );
281 );
282 }
283 return total;
284 }
unsigned int nbLabels(unsigned int x, unsigned int y) const

References DynArrayXYOfMap< Value >::nbLabels(), DynArrayXYOfMap< Value >::X, and DynArrayXYOfMap< Value >::Y.

◆ clear()

template<typename Value >
void DynArrayXYOfMap< Value >::clear ( )
inline

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

216 {
217 for ( unsigned int x = 0; x < X; ++x )
218 for ( unsigned int y = 0; y < Y; ++y )
219 _data[ offset( x, y ) ].clear();
220 }
size_t offset(unsigned int x, unsigned int y) const

References DynArrayXYOfMap< Value >::_data, DynArrayXYOfMap< Value >::offset(), DynArrayXYOfMap< Value >::X, and DynArrayXYOfMap< Value >::Y.

◆ display()

template<typename Value >
void DynArrayXYOfMap< Value >::display ( ostream &  ,
unsigned int  ,
unsigned int  ,
unsigned int   
)
inline

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

265 {}

◆ erase()

template<typename Value >
unsigned int DynArrayXYOfMap< Value >::erase ( unsigned int  l,
unsigned int  x,
unsigned int  y 
)
inline

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

229 {
230 return static_cast<unsigned int>(_data[ offset( x, y ) ].erase( l ));
231 }

References DynArrayXYOfMap< Value >::_data, and DynArrayXYOfMap< Value >::offset().

◆ getLabels()

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

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

251 {
252 labels.clear();
253 for ( ConstIterator it = _data[ offset( x, y ) ].begin(),
254 it_end = _data[ offset( x, y ) ].end();
255 it != it_end; ++it )
256 labels.push_back( (*it).first );
257 }
MyDigitalSurface::ConstIterator ConstIterator

References DynArrayXYOfMap< Value >::_data, and DynArrayXYOfMap< Value >::offset().

◆ hasLabel()

template<typename Value >
bool DynArrayXYOfMap< Value >::hasLabel ( unsigned int  l,
unsigned int  x,
unsigned int  y 
) const
inline

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

245 {
246 return _data[ offset( x, y ) ].count( l ) != 0;
247 }

References DynArrayXYOfMap< Value >::_data, and DynArrayXYOfMap< Value >::offset().

◆ nbLabels()

template<typename Value >
unsigned int DynArrayXYOfMap< Value >::nbLabels ( unsigned int  x,
unsigned int  y 
) const
inline

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

260 {
261 return static_cast<unsigned int>(_data[ offset( x, y ) ].size());
262 }

References DynArrayXYOfMap< Value >::_data, and DynArrayXYOfMap< Value >::offset().

Referenced by DynArrayXYOfMap< Value >::area().

◆ offset()

◆ setValue()

template<typename Value >
void DynArrayXYOfMap< Value >::setValue ( const Value val,
unsigned int  l,
unsigned int  x,
unsigned int  y 
)
inline

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

235 {
236 _data[ offset( x, y ) ][ l ] = val;
237 }

References DynArrayXYOfMap< Value >::_data, and DynArrayXYOfMap< Value >::offset().

◆ setValueNoNewLabel()

template<typename Value >
void DynArrayXYOfMap< Value >::setValueNoNewLabel ( const Value val,
unsigned int  l,
unsigned int  x,
unsigned int  y 
)
inline

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

240 {
241 _data[ offset( x, y ) ][ l ] = val;
242 }

References DynArrayXYOfMap< Value >::_data, and DynArrayXYOfMap< Value >::offset().

◆ value()

template<typename Value >
const Value & DynArrayXYOfMap< Value >::value ( unsigned int  l,
unsigned int  x,
unsigned int  y 
)
inline

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

224 {
225 return _data[ offset( x, y ) ][ l ];
226 }

References DynArrayXYOfMap< Value >::_data, and DynArrayXYOfMap< Value >::offset().

Field Documentation

◆ _data

◆ L

template<typename Value >
const unsigned int DynArrayXYOfMap< Value >::L

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

◆ X

◆ Y


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