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

Public Member Functions

 ArrayXYOfMap ()
void clear ()
const Value & value (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::map< unsigned int, Value > MyMap
typedef MyMap::const_iterator ConstIterator

Private Attributes

MyMap _data [X][Y]

Detailed Description

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

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 161 of file testLabelledMap-benchmark.cpp.

Member Typedef Documentation

◆ ConstIterator

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

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

◆ MyMap

template<typename Value, unsigned int L, unsigned int X, unsigned int Y>
typedef std::map<unsigned int, Value> ArrayXYOfMap< Value, L, X, Y >::MyMap
private

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

Constructor & Destructor Documentation

◆ ArrayXYOfMap()

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

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

169 {
170 }

Member Function Documentation

◆ area()

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

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

227 {
228 unsigned long long total = 0;
229 for ( unsigned int y = 0; y < Y; ++y )
230 for ( unsigned int x = 0; x < X; ++x )
231 {
232 unsigned int size = nbLabels( x, y );
233 total += ( size + 1 ) *
234 ( sizeof( Value ) // one value per node
235 + 3 * sizeof( Value* ) // three pointers
236 + 2 //_RbTreeColor { _S_red = false, _S_black = true };
237 + 8 // dynamic allocation );
238 );
239 }
240 return total;
241 }
unsigned int nbLabels(unsigned int x, unsigned int y) const

References nbLabels().

◆ clear()

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

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

174 {
175 for ( unsigned int y = 0; y < Y; ++y )
176 for ( unsigned int x = 0; x < X; ++x )
177 _data[ x ][ y ].clear();
178 }

References _data, and clear().

Referenced by clear().

◆ display()

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

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

222 {}

◆ erase()

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

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

187 {
188 return _data[ x ][ y ].erase( l );
189 }

References _data.

◆ getLabels()

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

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

209 {
210 labels.clear();
211 for ( ConstIterator it = _data[ x ][ y ].begin(), it_end = _data[ x ][ y ].end();
212 it != it_end; ++it )
213 labels.push_back( (*it).first );
214 }
MyMap::const_iterator ConstIterator

References _data.

◆ hasLabel()

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

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

203 {
204 return _data[ x ][ y ].count( l ) != 0;
205 }

References _data.

◆ nbLabels()

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

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

217 {
218 return (unsigned int)_data[ x ][ y ].size();
219 }

References _data.

Referenced by area().

◆ setValue()

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

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

193 {
194 _data[ x ][ y ][ l ] = val;
195 }

References _data.

◆ setValueNoNewLabel()

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

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

198 {
199 _data[ x ][ y ][ l ] = val;
200 }

References _data.

◆ value()

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

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

182 {
183 return _data[ x ][ y ][ l ];
184 }

References _data.

Field Documentation

◆ _data

template<typename Value, unsigned int L, unsigned int X, unsigned int Y>
MyMap ArrayXYOfMap< Value, L, X, Y >::_data[X][Y]
private

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