DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Data Fields
DGtal::IndexedListWithBlocks< TValue, N, M >::FirstBlock Struct Reference

#include <IndexedListWithBlocks.h>

Collaboration diagram for DGtal::IndexedListWithBlocks< TValue, N, M >::FirstBlock:
Collaboration graph
[legend]

Public Member Functions

 FirstBlock ()
void insert (unsigned int idx, const Value &v)
void erase (unsigned int idx)

Data Fields

unsigned int size
Value values [N]
ValueOrBlockPointer data

Detailed Description

template<typename TValue, unsigned int N, unsigned int M>
struct DGtal::IndexedListWithBlocks< TValue, N, M >::FirstBlock

Represents the first block in the container. Internal structure.

Definition at line 138 of file IndexedListWithBlocks.h.


Constructor & Destructor Documentation

template<typename TValue, unsigned int N, unsigned int M>
DGtal::IndexedListWithBlocks< TValue, N, M >::FirstBlock::FirstBlock ( )
inline

Definition at line 140 of file IndexedListWithBlocks.h.

: size( 0 )
{ data.nextBlock = 0; }

Member Function Documentation

template<typename TValue, unsigned int N, unsigned int M>
void DGtal::IndexedListWithBlocks< TValue, N, M >::FirstBlock::erase ( unsigned int  idx)
inline

Definition at line 194 of file IndexedListWithBlocks.h.

References DGtal::IndexedListWithBlocks< TValue, N, M >::FirstBlock::size.

{
// 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 value.
std::copy( values + idx + 1, values + size, values + idx );
data.nextBlock = 0;
}
else if ( size == N + 2 )
{
if ( idx < N )
{
std::copy( values + idx + 1, values + N, values + idx );
values[ N - 1 ] = data.nextBlock->values[ 0 ];
Value tmp = data.nextBlock->values[ 1 ];
delete data.nextBlock;
data.lastValue = tmp;
}
else if ( idx == N )
{
Value tmp = data.nextBlock->values[ 1 ];
delete data.nextBlock;
data.lastValue = tmp;
}
else // idx == N + 1
{
Value tmp = data.nextBlock->values[ 0 ];
delete data.nextBlock;
data.lastValue = tmp;
}
}
else // size > N + 2
{
if ( idx < N )
{
std::copy( values + idx + 1, values + N, values + idx );
values[ N - 1 ] = data.nextBlock->values[ 0 ];
data.nextBlock = data.nextBlock->erase( 0, size - N );
}
else
data.nextBlock = data.nextBlock->erase( idx - N, size - N );
}
--size;
}
template<typename TValue, unsigned int N, unsigned int M>
void DGtal::IndexedListWithBlocks< TValue, N, M >::FirstBlock::insert ( unsigned int  idx,
const Value v 
)
inline

Definition at line 144 of file IndexedListWithBlocks.h.

References DGtal::IndexedListWithBlocks< TValue, N, M >::FirstBlock::size, and DGtal::IndexedListWithBlocks< TValue, N, M >::AnyBlock::values.

{
if ( size <= N )
{
ASSERT( idx <= size );
// works also in the case we use 'data' to store a N+1-th value.
std::copy_backward( values + idx, values + size, values + size + 1 );
values[ idx ] = v;
}
else if ( size == (N+1) )
{
ASSERT( idx <= size );
// This cannot be tested.
// ASSERT( data.nextBlock == 0 );
AnyBlock* next = new AnyBlock;
if ( idx < N )
{
next->values[ 0 ] = values[ N - 1 ];
next->values[ 1 ] = data.lastValue;
std::copy_backward( values + idx, values + N - 1, values + N );
values[ idx ] = v;
}
else if ( idx == N )
{
next->values[ 0 ] = v;
next->values[ 1 ] = data.lastValue;
}
else if ( idx > N )
{
next->values[ 0 ] = data.lastValue;
next->values[ 1 ] = v;
}
data.nextBlock = next;
}
else // size > N + 1
{
if ( idx < N )
{
Value v1 = values[ N - 1 ];
std::copy_backward( values + idx, values + N - 1, values + N );
data.nextBlock->insert( 0, size - N, v1 );
values[ idx ] = v;
}
else
data.nextBlock->insert( idx - N, size - N, v );
}
++size;
}

Field Documentation

template<typename TValue, unsigned int N, unsigned int M>
ValueOrBlockPointer DGtal::IndexedListWithBlocks< TValue, N, M >::FirstBlock::data
template<typename TValue, unsigned int N, unsigned int M>
unsigned int DGtal::IndexedListWithBlocks< TValue, N, M >::FirstBlock::size
template<typename TValue, unsigned int N, unsigned int M>
Value DGtal::IndexedListWithBlocks< TValue, N, M >::FirstBlock::values[N]

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