DGtal  1.5.beta
DGtal::LabelledMap< TData, L, TWord, N, M >::__FirstBlock Struct Reference

#include <DGtal/base/LabelledMap.h>

Public Member Functions

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

Data Fields

Data datas [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; }

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( datas + idx + 1, datas + size, datas + idx );
258  data.nextBlock = 0;
259  }
260  else if ( size == N + 2 )
261  {
262  if ( idx < N )
263  {
264  std::copy( datas + idx + 1, datas + N, datas + idx );
265  datas[ N - 1 ] = data.nextBlock->datas[ 0 ];
266  Data tmp = data.nextBlock->datas[ 1 ];
267  delete data.nextBlock;
268  data.lastData = tmp;
269  }
270  else if ( idx == N )
271  {
272  Data tmp = data.nextBlock->datas[ 1 ];
273  delete data.nextBlock;
274  data.lastData = tmp;
275  }
276  else // idx == N + 1
277  {
278  Data tmp = data.nextBlock->datas[ 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( datas + idx + 1, datas + N, datas + idx );
288  datas[ N - 1 ] = data.nextBlock->datas[ 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  }

References DGtal::LabelledMap< TData, L, TWord, N, M >::__FirstBlock::datas.

◆ 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  {
190  std::copy_backward( datas + idx, datas + size, datas + size + 1 );
191  return ( datas[ idx ] = v );
192  }
193  else if ( size == N )
194  {
195  if ( idx < N )
196  {
197  data.lastData = datas[ N - 1 ];
198  std::copy_backward( datas + idx, datas + N - 1, datas + N );
199  return ( datas[ 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 );
210  __AnyBlock* next = new __AnyBlock;
211  if ( idx < N )
212  {
213  next->datas[ 0 ] = datas[ N - 1 ];
214  next->datas[ 1 ] = data.lastData;
215  std::copy_backward( datas + idx, datas + N - 1, datas + N );
216  data.nextBlock = next;
217  return ( datas[ idx ] = v );
218  }
219  else if ( idx == N )
220  {
221  next->datas[ 1 ] = data.lastData;
222  data.nextBlock = next;
223  return ( next->datas[ 0 ] = v );
224  }
225  else //if ( idx > N )
226  {
227  next->datas[ 0 ] = data.lastData;
228  data.nextBlock = next;
229  return ( next->datas[ 1 ] = v );
230  }
231  }
232  else // size > N + 1
233  {
234  if ( idx < N )
235  {
236  Data v1 = datas[ N - 1 ];
237  std::copy_backward( datas + idx, datas + N - 1, datas + N );
238  data.nextBlock->insert( 0, size - N, v1 );
239  return ( datas[ 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::datas, and DGtal::LabelledMap< TData, L, TWord, N, M >::__FirstBlock::datas.

Field Documentation

◆ 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.

◆ datas

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

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