DGtal 2.2.0
Loading...
Searching...
No Matches
DynArrayLXY< Value > Class Template Reference

Public Types

typedef Value ValueType

Public Member Functions

 DynArrayLXY (unsigned int _L, unsigned int _X, unsigned int _Y, Value invalid)
 ~DynArrayLXY ()
void clear ()
size_t offset (unsigned int l, unsigned int x, unsigned int y) const
const Value & value (unsigned int l, unsigned int x, unsigned int y) const
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 Attributes

Value * _data
Value _invalid

Detailed Description

template<typename Value>
class DynArrayLXY< Value >

Array[L][X][Y] of value. Brute-force. High memory consumption. Rather fast except when working with several labels.

Note that 4000*4000*16 is upper limit on my 8Gb laptop (2Gb). Note that 2000*2000*64 is upper limit on my 8Gb laptop (2Gb).

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

Member Typedef Documentation

◆ ValueType

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

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

Constructor & Destructor Documentation

◆ DynArrayLXY()

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

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

90 : L( _L ), X( _X ), Y( _Y )
91 {
93 _data = new Value[ L * X * Y ];
94 clear();
95 }
const unsigned int Y
const unsigned int L
const unsigned int X

References _data, _invalid, clear(), L, X, and Y.

◆ ~DynArrayLXY()

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

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

98 {
99 delete[] _data;
100 }

References _data.

Member Function Documentation

◆ area()

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

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

170 {
171 return L * X * Y * sizeof( Value );
172 }

References L, X, and Y.

◆ clear()

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

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

103 {
104 for ( unsigned int l = 0; l < L; ++l )
105 for ( unsigned int x = 0; x < X; ++x )
106 for ( unsigned int y = 0; y < Y; ++y )
107 setValue( _invalid, l, x, y );
108 }
void setValue(const Value &val, unsigned int l, unsigned int x, unsigned int y)

References _invalid, L, setValue(), X, and Y.

Referenced by DynArrayLXY().

◆ display()

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

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

166 {}

◆ erase()

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

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

122 {
123 size_t offs = offset( l, x, y );
124 if ( _data[ offs ] != _invalid )
125 {
126 _data[ offs ] = _invalid;
127 return 1;
128 }
129 return 0;
130 }
size_t offset(unsigned int l, unsigned int x, unsigned int y) const

References _data, _invalid, and offset().

◆ getLabels()

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

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

150 {
151 labels.clear();
152 for ( unsigned int l = 0; l < L; ++l )
153 if ( hasLabel( l, x, y ) )
154 labels.push_back( l );
155 }
bool hasLabel(unsigned int l, unsigned int x, unsigned int y) const

References hasLabel(), and L.

◆ hasLabel()

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

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

144 {
145 return value( l, x, y ) != _invalid;
146 }
const Value & value(unsigned int l, unsigned int x, unsigned int y) const

References _invalid, and value().

Referenced by getLabels(), and nbLabels().

◆ nbLabels()

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

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

158 {
159 unsigned int nb = 0;
160 for ( unsigned int l = 0; l < L; ++l )
161 if ( hasLabel( l, x, y ) ) ++nb;
162 return nb;
163 }

References hasLabel(), and L.

◆ offset()

template<typename Value>
size_t DynArrayLXY< Value >::offset ( unsigned int l,
unsigned int x,
unsigned int y ) const
inline

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

112 {
113 return ( ( l * X ) + x ) * Y + y;
114 }

References X, and Y.

Referenced by erase(), setValue(), setValueNoNewLabel(), and value().

◆ setValue()

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

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

134 {
135 _data[ offset( l, x, y ) ] = val;
136 }

References _data, and offset().

Referenced by clear().

◆ setValueNoNewLabel()

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

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

139 {
140 _data[ offset( l, x, y ) ] = val;
141 }

References _data, and offset().

◆ value()

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

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

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

References _data, and offset().

Referenced by hasLabel().

Field Documentation

◆ _data

template<typename Value>
Value* DynArrayLXY< Value >::_data
private

◆ _invalid

template<typename Value>
Value DynArrayLXY< Value >::_invalid
private

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

Referenced by clear(), DynArrayLXY(), erase(), and hasLabel().

◆ L

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

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

Referenced by area(), clear(), DynArrayLXY(), getLabels(), and nbLabels().

◆ X

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

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

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

◆ Y

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

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

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


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