DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | Data Fields | Private Types | Private Attributes
DynArrayXYOfMap< Value > Class Template Reference
Collaboration diagram for DynArrayXYOfMap< Value >:
Collaboration graph
[legend]

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 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 &out, unsigned int l, unsigned int x, unsigned int y)
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,
Value > 
MyMap
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 186 of file testMultiMap-benchmark.cpp.


Member Typedef Documentation

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

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

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

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

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

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


Constructor & Destructor Documentation

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

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

: L( _L ), X( _X ), Y( _Y )
{
_data = new MyMap[ X * Y ];
}
template<typename Value >
DynArrayXYOfMap< Value >::~DynArrayXYOfMap ( )
inline

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

{
delete[] _data;
}

Member Function Documentation

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

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

{
unsigned long long total = 0;
for ( unsigned int y = 0; y < Y; ++y )
for ( unsigned int x = 0; x < X; ++x )
{
unsigned int size = nbLabels( x, y );
total += ( size + 1 ) *
( sizeof( Value ) // one value per node
+ 3 * sizeof( Value* ) // three pointers
+ 2 //_RbTreeColor { _S_red = false, _S_black = true };
+ 8 // dynamic allocation );
);
}
return total;
}
template<typename Value >
void DynArrayXYOfMap< Value >::clear ( )
inline

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

References DynArrayXYOfMap< Value >::clear().

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

{
for ( unsigned int x = 0; x < X; ++x )
for ( unsigned int y = 0; y < Y; ++y )
_data[ offset( x, y ) ].clear();
}
template<typename Value >
void DynArrayXYOfMap< Value >::display ( ostream &  out,
unsigned int  l,
unsigned int  x,
unsigned int  y 
)
inline

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

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

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

{
return _data[ offset( x, y ) ].erase( l );
}
template<typename Value >
void DynArrayXYOfMap< Value >::getLabels ( std::vector< unsigned int > &  labels,
unsigned int  x,
unsigned int  y 
) const
inline

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

{
labels.clear();
for ( ConstIterator it = _data[ offset( x, y ) ].begin(),
it_end = _data[ offset( x, y ) ].end();
it != it_end; ++it )
labels.push_back( (*it).first );
}
template<typename Value >
bool DynArrayXYOfMap< Value >::hasLabel ( unsigned int  l,
unsigned int  x,
unsigned int  y 
) const
inline

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

{
return _data[ offset( x, y ) ].count( l ) != 0;
}
template<typename Value >
unsigned int DynArrayXYOfMap< Value >::nbLabels ( unsigned int  x,
unsigned int  y 
) const
inline

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

{
return _data[ offset( x, y ) ].size();
}
template<typename Value >
size_t DynArrayXYOfMap< Value >::offset ( unsigned int  x,
unsigned int  y 
) const
inline

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

{
return x * Y + y;
}
template<typename Value >
void DynArrayXYOfMap< Value >::setValue ( const Value &  val,
unsigned int  l,
unsigned int  x,
unsigned int  y 
)
inline

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

{
_data[ offset( x, y ) ][ l ] = val;
}
template<typename Value >
void DynArrayXYOfMap< Value >::setValueNoNewLabel ( const Value &  val,
unsigned int  l,
unsigned int  x,
unsigned int  y 
)
inline

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

{
_data[ offset( x, y ) ][ l ] = val;
}
template<typename Value >
const Value& DynArrayXYOfMap< Value >::value ( unsigned int  l,
unsigned int  x,
unsigned int  y 
)
inline

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

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

Field Documentation

template<typename Value >
MyMap* DynArrayXYOfMap< Value >::_data
private

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

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

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

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

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

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

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


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