DGtal 2.2.0
Loading...
Searching...
No Matches
DGtal::LabelledMap< TData, L, TWord, N, M >::__FirstBlock Struct Reference

#include <DGtal/base/LabelledMap.h>

Public Member Functions

 __FirstBlock ()
Data & insert (size_t idx, size_t size, const Data &v)
void erase (size_t idx, size_t size)

Data Fields

Data allData [N]
DataOrBlockPointer data

Detailed Description

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
struct DGtal::LabelledMap< TData, L, TWord, N, M >::__FirstBlock

Represents the first block in the container. Internal structure.

Definition at line 179 of file LabelledMap.h.

Constructor & Destructor Documentation

◆ __FirstBlock()

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::__FirstBlock::__FirstBlock ( )
inline

Definition at line 181 of file LabelledMap.h.

182 { data.nextBlock = 0; }

References data, and DGtal::LabelledMap< TData, L, TWord, N, M >::DataOrBlockPointer::nextBlock.

Member Function Documentation

◆ erase()

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
void DGtal::LabelledMap< TData, L, TWord, N, M >::__FirstBlock::erase ( size_t idx,
size_t size )
inline

Definition at line 247 of file LabelledMap.h.

248 {
249 // std::cerr << "__FirstBlock::erase(" << idx << ")"
250 // << " this=" << this
251 // << " next=" << data.nextBlock
252 // << std::endl;
253 ASSERT( idx < size );
254 if ( size <= ( N + 1 ) )
255 {
256 // works also in the case we use 'data' to store a N+1-th data.
257 std::copy( allData + idx + 1, allData + size, allData + idx );
258 data.nextBlock = 0;
259 }
260 else if ( size == N + 2 )
261 {
262 if ( idx < N )
263 {
264 std::copy( allData + idx + 1, allData + N, allData + idx );
265 allData[ N - 1 ] = data.nextBlock->allData[ 0 ];
266 Data tmp = data.nextBlock->allData[ 1 ];
267 delete data.nextBlock;
268 data.lastData = tmp;
269 }
270 else if ( idx == N )
271 {
272 Data tmp = data.nextBlock->allData[ 1 ];
273 delete data.nextBlock;
274 data.lastData = tmp;
275 }
276 else // idx == N + 1
277 {
278 Data tmp = data.nextBlock->allData[ 0 ];
279 delete data.nextBlock;
280 data.lastData = tmp;
281 }
282 }
283 else // size > N + 2
284 {
285 if ( idx < N )
286 {
287 std::copy( allData + idx + 1, allData + N, allData + idx );
288 allData[ N - 1 ] = data.nextBlock->allData[ 0 ];
289 data.nextBlock = data.nextBlock->erase( 0, size - N );
290 }
291 else
292 data.nextBlock = data.nextBlock->erase( idx - N, size - N );
293 }
294 }
Aim: Represents a map label -> data, where the label is an integer between 0 and a constant L-1....

References DGtal::LabelledMap< TData, L, TWord, N, M >::__AnyBlock::allData, allData, data, DGtal::LabelledMap< TData, L, TWord, N, M >::__AnyBlock::erase(), DGtal::LabelledMap< TData, L, TWord, N, M >::DataOrBlockPointer::lastData, DGtal::LabelledMap< TData, L, TWord, N, M >::DataOrBlockPointer::nextBlock, and DGtal::LabelledMap< TData, L, TWord, N, M >::size().

◆ insert()

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
Data & DGtal::LabelledMap< TData, L, TWord, N, M >::__FirstBlock::insert ( size_t idx,
size_t size,
const Data & v )
inline

Definition at line 185 of file LabelledMap.h.

186 {
187 ASSERT( idx <= size );
188 if ( size < N )
189 {
191 return ( allData[ idx ] = v );
192 }
193 else if ( size == N )
194 {
195 if ( idx < N )
196 {
197 data.lastData = allData[ N - 1 ];
199 return ( allData[ idx ] = v );
200 }
201 else // idx == N
202 {
203 return ( data.lastData = v );
204 }
205 }
206 else if ( size == (N+1) )
207 {
208 // This cannot be tested.
209 // ASSERT( data.nextBlock == 0 );
211 if ( idx < N )
212 {
213 next->allData[ 0 ] = allData[ N - 1 ];
214 next->allData[ 1 ] = data.lastData;
216 data.nextBlock = next;
217 return ( allData[ idx ] = v );
218 }
219 else if ( idx == N )
220 {
221 next->allData[ 1 ] = data.lastData;
222 data.nextBlock = next;
223 return ( next->allData[ 0 ] = v );
224 }
225 else //if ( idx > N )
226 {
227 next->allData[ 0 ] = data.lastData;
228 data.nextBlock = next;
229 return ( next->allData[ 1 ] = v );
230 }
231 }
232 else // size > N + 1
233 {
234 if ( idx < N )
235 {
236 Data v1 = allData[ N - 1 ];
238 data.nextBlock->insert( 0, size - N, v1 );
239 return ( allData[ idx ] = v );
240 }
241 else
242 return data.nextBlock->insert( idx - N, size - N, v );
243 }
244 }

References DGtal::LabelledMap< TData, L, TWord, N, M >::__AnyBlock::allData, allData, data, DGtal::LabelledMap< TData, L, TWord, N, M >::__AnyBlock::insert(), DGtal::LabelledMap< TData, L, TWord, N, M >::DataOrBlockPointer::lastData, DGtal::LabelledMap< TData, L, TWord, N, M >::DataOrBlockPointer::nextBlock, and DGtal::LabelledMap< TData, L, TWord, N, M >::size().

Field Documentation

◆ allData

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
Data DGtal::LabelledMap< TData, L, TWord, N, M >::__FirstBlock::allData[N]

Definition at line 296 of file LabelledMap.h.

Referenced by erase(), and insert().

◆ data

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
DataOrBlockPointer DGtal::LabelledMap< TData, L, TWord, N, M >::__FirstBlock::data

Definition at line 297 of file LabelledMap.h.

Referenced by __FirstBlock(), erase(), and insert().


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