DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Data Fields
DGtal::LabelledMap< TData, L, TWord, N, M >::__FirstBlock Struct Reference

#include <LabelledMap.h>

Collaboration diagram for DGtal::LabelledMap< TData, L, TWord, N, M >::__FirstBlock:
Collaboration graph
[legend]

Public Member Functions

 __FirstBlock ()
Datainsert (unsigned int idx, unsigned int size, const Data &v)
void erase (unsigned int idx, unsigned int 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

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.

{ data.nextBlock = 0; }

Member Function Documentation

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

Definition at line 247 of file LabelledMap.h.

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

{
// std::cerr << "__FirstBlock::erase(" << idx << ")"
// << " this=" << this
// << " next=" << data.nextBlock
// << std::endl;
ASSERT( idx < size );
if ( size <= ( N + 1 ) )
{
// works also in the case we use 'data' to store a N+1-th data.
std::copy( datas + idx + 1, datas + size, datas + idx );
data.nextBlock = 0;
}
else if ( size == N + 2 )
{
if ( idx < N )
{
std::copy( datas + idx + 1, datas + N, datas + idx );
datas[ N - 1 ] = data.nextBlock->datas[ 0 ];
Data tmp = data.nextBlock->datas[ 1 ];
delete data.nextBlock;
data.lastData = tmp;
}
else if ( idx == N )
{
Data tmp = data.nextBlock->datas[ 1 ];
delete data.nextBlock;
data.lastData = tmp;
}
else // idx == N + 1
{
Data tmp = data.nextBlock->datas[ 0 ];
delete data.nextBlock;
data.lastData = tmp;
}
}
else // size > N + 2
{
if ( idx < N )
{
std::copy( datas + idx + 1, datas + N, datas + idx );
datas[ N - 1 ] = data.nextBlock->datas[ 0 ];
data.nextBlock = data.nextBlock->erase( 0, size - N );
}
else
data.nextBlock = data.nextBlock->erase( idx - N, size - N );
}
}
template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
Data& DGtal::LabelledMap< TData, L, TWord, N, M >::__FirstBlock::insert ( unsigned int  idx,
unsigned int  size,
const Data v 
)
inline

Definition at line 185 of file LabelledMap.h.

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

{
ASSERT( idx <= size );
if ( size < N )
{
std::copy_backward( datas + idx, datas + size, datas + size + 1 );
return ( datas[ idx ] = v );
}
else if ( size == N )
{
if ( idx < N )
{
data.lastData = datas[ N - 1 ];
std::copy_backward( datas + idx, datas + N - 1, datas + N );
return ( datas[ idx ] = v );
}
else // idx == N
{
return ( data.lastData = v );
}
}
else if ( size == (N+1) )
{
// This cannot be tested.
// ASSERT( data.nextBlock == 0 );
__AnyBlock* next = new __AnyBlock;
if ( idx < N )
{
next->datas[ 0 ] = datas[ N - 1 ];
next->datas[ 1 ] = data.lastData;
std::copy_backward( datas + idx, datas + N - 1, datas + N );
data.nextBlock = next;
return ( datas[ idx ] = v );
}
else if ( idx == N )
{
next->datas[ 1 ] = data.lastData;
data.nextBlock = next;
return ( next->datas[ 0 ] = v );
}
else //if ( idx > N )
{
next->datas[ 0 ] = data.lastData;
data.nextBlock = next;
return ( next->datas[ 1 ] = v );
}
}
else // size > N + 1
{
if ( idx < N )
{
Data v1 = datas[ N - 1 ];
std::copy_backward( datas + idx, datas + N - 1, datas + N );
data.nextBlock->insert( 0, size - N, v1 );
return ( datas[ idx ] = v );
}
else
return data.nextBlock->insert( idx - N, size - N, v );
}
}

Field Documentation

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
DataOrBlockPointer DGtal::LabelledMap< TData, L, TWord, N, M >::__FirstBlock::data
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: