DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Data Structures | Public Types | Public Member Functions | Private Member Functions | Private Attributes
DGtal::LabelledMap< TData, L, TWord, N, M > Class Template Reference

#include <LabelledMap.h>

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

Data Structures

struct  __AnyBlock
struct  __FirstBlock
class  BlockConstIterator
class  BlockIterator
union  BlockPointer
class  ConstIterator
union  DataOrBlockPointer
 Used in first block to finish it or to point to the next block. More...
class  KeyCompare
 Key comparator class. Always natural ordering. More...
class  ValueCompare
 Value comparator class. Always natural ordering between keys. More...

Public Types

typedef LabelledMap< TData, L,
TWord, N, M > 
Self
typedef TData Data
typedef TWord Word
typedef Labels< L, WordLabelsType
typedef LabelsType::Label Label
typedef Label Key
typedef std::pair< const Key,
Data
Value
typedef LabelsType::ConstIterator LabelsConstIterator
typedef std::ptrdiff_t DifferenceType
typedef std::size_t SizeType
typedef ValueReference
typedef ValuePointer
typedef const ValueConstReference
typedef const ValueConstPointer
typedef Key key_type
typedef Value value_type
typedef Data data_type
typedef Data mapped_type
typedef DifferenceType difference_type
typedef Reference reference
typedef Pointer pointer
typedef ConstReference const_reference
typedef ConstPointer const_pointer
typedef SizeType size_type
typedef ConstIterator iterator
typedef ConstIterator const_iterator
typedef KeyCompare key_compare
typedef ValueCompare value_compare
typedef ConstIterator Iterator

Public Member Functions

 LabelledMap ()
 LabelledMap (const LabelledMap &other)
template<typename InputIterator >
 LabelledMap (InputIterator first, InputIterator last)
LabelledMapoperator= (const LabelledMap &other)
 ~LabelledMap ()
const LabelsTypelabels () const
SizeType size () const
bool empty () const
SizeType max_size () const
SizeType capacity () const
KeyCompare key_comp () const
ValueCompare value_comp () const
void swap (Self &other)
void clear ()
SizeType count (const Key &key) const
Dataoperator[] (const Key &key)
const Dataoperator[] (const Key &key) const
DatafastAt (const Key &key)
const DatafastAt (const Key &key) const
std::pair< Iterator, bool > insert (const Value &val)
Iterator insert (Iterator position, const Value &val)
template<typename InputIterator >
void insert (InputIterator first, InputIterator last)
void erase (Iterator position)
SizeType erase (Key key)
void erase (Iterator first, Iterator last)
ConstIterator begin () const
ConstIterator end () const
Iterator begin ()
Iterator end ()
std::pair< Iterator, Iteratorequal_range (const Key &x)
std::pair< ConstIterator,
ConstIterator
equal_range (const Key &x) const
Iterator find (const Key &x)
ConstIterator find (const Key &x) const
Iterator lower_bound (const Key &x)
ConstIterator lower_bound (const Key &x) const
Iterator upper_bound (const Key &x)
ConstIterator upper_bound (const Key &x) const
void blockClear (unsigned int size)
DatablockAt (unsigned int idx)
const DatablockAt (unsigned int idx) const
DatablockInsert (unsigned int idx, unsigned int block_size, const Data &data)
void blockErase (unsigned int idx)
BlockIterator blockBegin ()
BlockIterator blockEnd ()
BlockConstIterator blockBegin () const
BlockConstIterator blockEnd () const
void selfDisplay (std::ostream &out) const
bool isValid () const

Private Member Functions

 BOOST_STATIC_ASSERT (L >=1)
 BOOST_STATIC_ASSERT (N >=0)
 BOOST_STATIC_ASSERT (M >=2)

Private Attributes

LabelsType myLabels
__FirstBlock myFirstBlock

Detailed Description

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

Aim: Represents a map label -> data, where the label is an integer between 0 and a constant L-1. It is based on a binary coding of labels and a mixed list/array structure. The assumption is that the number of used labels is much less than L. The objective is to minimize the memory usage.

 Description of template class 'LabelledMap' <p>     Model of boost::AssociativeContainer,
 boost::PairAssociativeContainer,
 boost::UniqueAssociativeContainer. As such, it is refinement of
 boost::ForwardContainer and boost::Container.  It is also a model
 of boost::Assignable, boost::CopyConstructible.
V[ 0 ] is the data of the first set label.
V[ 1 ] is the data of the second set label.
...

if less than 3 datas and N = 2
+------+------+------+------+------+
|labels| V[0] | V[1] | ...  |  0   |
+------+------+------+------+------+

if only 3 datas and N = 2
+------+------+------+------+------+
|labels| V[0] | V[1] | V[2] | V[3] |
+------+------+------+------+------+

if more than 3 datas and N = 2, M = 4
+------+------+------+------+------+        +------+------+------+------+------+
|labels| V[0] | V[1] | V[2] | ptr --------> | V[3] | V[4] | V[5] | V[6] | ptr --------> ...
+------+------+------+------+------+        +------+------+------+------+------+
 This structure is related to the IndexedListWithBlocks, except
 that it stores the mapping label -> index. The (maximum) number
 of possible labels is fixed at instantiation for optimisation
 purposes.

 Such a structure is useful when:
 - the expected size of this container is small, but may sometimes increase.
 - the user wishes sometimes to insert a new data or erase another data.
 - the user wishes to have an access to the datas that is as fast as possible given a valid label.
 - one wishes to limit as possible the memory usage.
 - generally this structure is embedded as the data of a big array.

 Model of boost::PairAssociativeContainer and
 boost::SimpleAssociativeContainer.

 @tparam TData the type for the datas stored in the list.
 @tparam L the maximum number of labels.
 @tparam TWord the integer used to store the labels (if L >= log_2( digits( TWord ) ) then several consecutive words are stored.), e.g. DGtal::uint8_t.
 @tparam N the number of data stored in the first block.
 @tparam M the number of data stored in the further blocks.

 NB: In the following, we use the notations
 - n is the size of the container
 - b is the number of blocks ( b = 1 + (size()-N) / M ).

Definition at line 119 of file LabelledMap.h.


Member Typedef Documentation

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef ConstIterator DGtal::LabelledMap< TData, L, TWord, N, M >::const_iterator

Definition at line 159 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef ConstPointer DGtal::LabelledMap< TData, L, TWord, N, M >::const_pointer

Definition at line 156 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef ConstReference DGtal::LabelledMap< TData, L, TWord, N, M >::const_reference

Definition at line 155 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef const Value* DGtal::LabelledMap< TData, L, TWord, N, M >::ConstPointer

Definition at line 141 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef const Value& DGtal::LabelledMap< TData, L, TWord, N, M >::ConstReference

Definition at line 140 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef TData DGtal::LabelledMap< TData, L, TWord, N, M >::Data

Definition at line 127 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef Data DGtal::LabelledMap< TData, L, TWord, N, M >::data_type

Definition at line 150 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef DifferenceType DGtal::LabelledMap< TData, L, TWord, N, M >::difference_type

Definition at line 152 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef std::ptrdiff_t DGtal::LabelledMap< TData, L, TWord, N, M >::DifferenceType

Definition at line 136 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef ConstIterator DGtal::LabelledMap< TData, L, TWord, N, M >::iterator

Definition at line 158 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef ConstIterator DGtal::LabelledMap< TData, L, TWord, N, M >::Iterator

non-mutable class via iterators.

Definition at line 730 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef Label DGtal::LabelledMap< TData, L, TWord, N, M >::Key

Definition at line 131 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef KeyCompare DGtal::LabelledMap< TData, L, TWord, N, M >::key_compare

Definition at line 160 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef Key DGtal::LabelledMap< TData, L, TWord, N, M >::key_type

Definition at line 146 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef LabelsType::Label DGtal::LabelledMap< TData, L, TWord, N, M >::Label

Definition at line 130 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef LabelsType::ConstIterator DGtal::LabelledMap< TData, L, TWord, N, M >::LabelsConstIterator

Definition at line 135 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef Labels<L, Word> DGtal::LabelledMap< TData, L, TWord, N, M >::LabelsType

Definition at line 129 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef Data DGtal::LabelledMap< TData, L, TWord, N, M >::mapped_type

Definition at line 151 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef Value* DGtal::LabelledMap< TData, L, TWord, N, M >::Pointer

Definition at line 139 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef Pointer DGtal::LabelledMap< TData, L, TWord, N, M >::pointer

Definition at line 154 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef Value& DGtal::LabelledMap< TData, L, TWord, N, M >::Reference

Definition at line 138 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef Reference DGtal::LabelledMap< TData, L, TWord, N, M >::reference

Definition at line 153 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef LabelledMap<TData, L, TWord, N, M> DGtal::LabelledMap< TData, L, TWord, N, M >::Self

Definition at line 126 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef SizeType DGtal::LabelledMap< TData, L, TWord, N, M >::size_type

Definition at line 157 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef std::size_t DGtal::LabelledMap< TData, L, TWord, N, M >::SizeType

Definition at line 137 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef std::pair<const Key, Data> DGtal::LabelledMap< TData, L, TWord, N, M >::Value

Definition at line 132 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef ValueCompare DGtal::LabelledMap< TData, L, TWord, N, M >::value_compare

Definition at line 161 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef Value DGtal::LabelledMap< TData, L, TWord, N, M >::value_type

Definition at line 149 of file LabelledMap.h.

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
typedef TWord DGtal::LabelledMap< TData, L, TWord, N, M >::Word

Definition at line 128 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 >::LabelledMap ( )
inline

Constructor.

Definition at line 539 of file LabelledMap.ih.

{ // default constructor of myLabels and myFirstBlock is automatically called.
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::LabelledMap ( const LabelledMap< TData, L, TWord, N, M > &  other)
inline

Copy constructor.

Parameters:
otherthe object to clone.

Definition at line 554 of file LabelledMap.ih.

References DGtal::LabelledMap< TData, L, TWord, N, M >::__FirstBlock::data, DGtal::LabelledMap< TData, L, TWord, N, M >::myFirstBlock, DGtal::LabelledMap< TData, L, TWord, N, M >::myLabels, DGtal::LabelledMap< TData, L, TWord, N, M >::DataOrBlockPointer::nextBlock, and DGtal::LabelledMap< TData, L, TWord, N, M >::size().

: myFirstBlock( other.myFirstBlock )
{
unsigned int s = N + 1; // there is one more stored data in the last block.
const __AnyBlock* nextBlock = other.myFirstBlock.data.nextBlock;
__AnyBlock** currentPointer = & myFirstBlock.data.nextBlock;
myLabels = other.myLabels;
while ( s < size() )
{
*currentPointer = new __AnyBlock( *nextBlock );
s += M;
currentPointer = & ( currentPointer->data.nextBlock );
}
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
template<typename InputIterator >
DGtal::LabelledMap< TData, L, TWord, N, M >::LabelledMap ( InputIterator  first,
InputIterator  last 
)
inline

Constructor from range.

Template Parameters:
InputIteratormodel of boost::InputIterator whose value type is convertible to Value.
Parameters:
firstan iterator on the first value of the range.
lastan iterator after the last value of the range.

Definition at line 573 of file LabelledMap.ih.

{ // default constructor of myLabels and myFirstBlock is automatically called.
BOOST_CONCEPT_ASSERT(( boost::InputIterator< InputIterator > ));
for ( ; first != last; ++first )
{
this->operator[]( first->first ) = first->second;
}
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::~LabelledMap ( )
inline

Member Function Documentation

template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::ConstIterator DGtal::LabelledMap< TData, L, TWord, N, M >::begin ( ) const
inline
Returns:
an iterator pointing on the first element in the container.

Definition at line 1099 of file LabelledMap.ih.

{
return ConstIterator( myLabels.begin(), blockBegin() );
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::Iterator DGtal::LabelledMap< TData, L, TWord, N, M >::begin ( )
inline
Returns:
an iterator pointing on the first element in the container.

Definition at line 1079 of file LabelledMap.ih.

References DGtal::LabelledMap< TData, L, TWord, N, M >::blockBegin().

{
const Self* ptr = (const Self *) this;
return Iterator( myLabels.begin(), ptr->blockBegin() );
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::Data & DGtal::LabelledMap< TData, L, TWord, N, M >::blockAt ( unsigned int  idx)
inline

Random unprotected read-write access to data at position idx

Parameters:
idxthe index of the data in the container.
Returns:
a reference on the data.
Precondition:
idx < size() NB: O( b ), E = O( 1 + ceil( ( idx - N ) / M ) )

Definition at line 747 of file LabelledMap.ih.

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

{
ASSERT( idx < size() );
if ( idx < N )
return myFirstBlock.datas[ idx ];
else if ( ( idx == N ) && ( size() == N+1 ) )
__AnyBlock* ptr = myFirstBlock.data.nextBlock;
idx -= N;
while ( idx >= M )
{
idx -= M;
ptr = ptr->next;
}
ASSERT( ptr != 0 );
return ptr->datas[ idx ];
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
const DGtal::LabelledMap< TData, L, TWord, N, M >::Data & DGtal::LabelledMap< TData, L, TWord, N, M >::blockAt ( unsigned int  idx) const
inline

Random unprotected read access to data at position idx

Parameters:
idxthe index of the data in the container.
Returns:
a const reference on the data.
Precondition:
idx < size() NB: O( b ), E = O( 1 + ceil( ( idx - N ) / M ) )

Definition at line 725 of file LabelledMap.ih.

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

{
ASSERT( idx < size() );
if ( idx < N )
return myFirstBlock.datas[ idx ];
else if ( ( idx == N ) && ( size() == N+1 ) )
const __AnyBlock* ptr = myFirstBlock.data.nextBlock;
idx -= N;
while ( idx >= M )
{
idx -= M;
ptr = ptr->next;
}
ASSERT( ptr != 0 );
return ptr->datas[ idx ];
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::BlockIterator DGtal::LabelledMap< TData, L, TWord, N, M >::blockBegin ( )
inline
Returns:
an iterator pointing on the first element in the container.

Definition at line 1117 of file LabelledMap.ih.

Referenced by DGtal::LabelledMap< TData, L, TWord, N, M >::begin().

{
return BlockIterator( myFirstBlock, 0, size() );
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::BlockConstIterator DGtal::LabelledMap< TData, L, TWord, N, M >::blockBegin ( ) const
inline
Returns:
an iterator pointing on the first element in the container.

Definition at line 1136 of file LabelledMap.ih.

{
return BlockConstIterator( myFirstBlock, 0, size() );
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
void DGtal::LabelledMap< TData, L, TWord, N, M >::blockClear ( unsigned int  size)
inline

Removes all the datas stored in the block structure.

Parameters:
sizemust be the current size of the block structure.

Definition at line 622 of file LabelledMap.ih.

References DGtal::LabelledMap< TData, L, TWord, N, M >::__AnyBlock::next.

Referenced by DGtal::LabelledMap< TData, L, TWord, N, M >::~LabelledMap().

{
if ( theSize != N+1 )
{
__AnyBlock* nextBlock = myFirstBlock.data.nextBlock;
while ( nextBlock != 0 )
{
__AnyBlock* ptr = nextBlock;
nextBlock = nextBlock->next;
delete ptr;
}
}
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::BlockIterator DGtal::LabelledMap< TData, L, TWord, N, M >::blockEnd ( )
inline
Returns:
an iterator pointing after the last element in the container.

Definition at line 1126 of file LabelledMap.ih.

Referenced by DGtal::LabelledMap< TData, L, TWord, N, M >::end().

{
SizeType s = size();
return BlockIterator( myFirstBlock, s, s );
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::BlockConstIterator DGtal::LabelledMap< TData, L, TWord, N, M >::blockEnd ( ) const
inline
Returns:
an iterator pointing after the last element in the container.

Definition at line 1145 of file LabelledMap.ih.

{
SizeType s = size();
return BlockConstIterator( myFirstBlock, s, s );
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
void DGtal::LabelledMap< TData, L, TWord, N, M >::blockErase ( unsigned int  idx)
inline

Removal of a data at a given position. Following datas are shifted.

Parameters:
idxthe index of the data in the container.
Precondition:
idx < size() NB: O( n ), E = O( n - idx )

Definition at line 1069 of file LabelledMap.ih.

{
ASSERT( idx < size() ); // end is not ok.
myFirstBlock.erase( idx, size() );
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::Data & DGtal::LabelledMap< TData, L, TWord, N, M >::blockInsert ( unsigned int  idx,
unsigned int  block_size,
const Data data 
)
inline

Insertion of a new data at given position. The former data at this position and the next ones are shifted.

Parameters:
idxthe index of the data in the container.
Precondition:
idx <= size() (if size(), inserts at the end.
Parameters:
datathe data to insert. NB: O( n ), E = O( n - idx )

Definition at line 1059 of file LabelledMap.ih.

{
ASSERT( idx <= block_size ); // end is ok.
return myFirstBlock.insert( idx, block_size, data );
}
template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::BOOST_STATIC_ASSERT ( L >=  1)
private
template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::BOOST_STATIC_ASSERT ( N >=  0)
private
template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::BOOST_STATIC_ASSERT ( M >=  2)
private
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::SizeType DGtal::LabelledMap< TData, L, TWord, N, M >::capacity ( ) const
inline

The number of datas currently allocated in the structure.

Definition at line 677 of file LabelledMap.ih.

{
return ( size() <= (N+1) )
? N+1
: ( 1 + ( size() - 1 - N ) / M ) * M + N;
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
void DGtal::LabelledMap< TData, L, TWord, N, M >::clear ( )
inline

Removes all the datas stored in the structure.

Definition at line 612 of file LabelledMap.ih.

template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::SizeType DGtal::LabelledMap< TData, L, TWord, N, M >::count ( const Key key) const
inline

Follows std::count.

Parameters:
keyany label
Returns:
0 if the key is not present in container, 1 otherwise.

Definition at line 716 of file LabelledMap.ih.

Referenced by DGtal::LabelledMap< TData, L, TWord, N, M >::size().

{
return myLabels.test( key ) ? 1 : 0;
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
bool DGtal::LabelledMap< TData, L, TWord, N, M >::empty ( ) const
inline
Returns:
'true' if and only if the container is empty. O(1)

Definition at line 659 of file LabelledMap.ih.

{
return size() == 0;
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::ConstIterator DGtal::LabelledMap< TData, L, TWord, N, M >::end ( ) const
inline
Returns:
an iterator pointing after the last element in the container.

Definition at line 1108 of file LabelledMap.ih.

{
return ConstIterator( myLabels.end(), blockEnd() );
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::Iterator DGtal::LabelledMap< TData, L, TWord, N, M >::end ( )
inline
Returns:
an iterator pointing after the last element in the container.

Definition at line 1089 of file LabelledMap.ih.

References DGtal::LabelledMap< TData, L, TWord, N, M >::blockEnd().

{
const Self* ptr = (const Self *) this;
return Iterator( myLabels.end(), ptr->blockEnd() );
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
std::pair< typename DGtal::LabelledMap< TData, L, TWord, N, M >::Iterator, typename DGtal::LabelledMap< TData, L, TWord, N, M >::Iterator > DGtal::LabelledMap< TData, L, TWord, N, M >::equal_range ( const Key x)
inline

Get range of equal elements.

Returns the bounds of a range that includes all the elements in the container with a key that compares equal to x. Here, the range will include one element at most.

If x does not match any key in the container, the range returned has a length of zero, with both iterators pointing to the element with nearest key greater than x, if any, or to map::end if x is greater than all the elements in the container.

Parameters:
xany key in 0..L-1
Returns:
a pair, where its member pair::first is an iterator to the lower bound of the range with the same value as the one that would be returned by lower_bound(x), and pair::second is an iterator to the upper bound of the range with the same value as the one that would be returned by upper_bound(x).

Definition at line 935 of file LabelledMap.ih.

{
Iterator it = begin(), it_end = end();
for ( ; it != it_end; ++it )
{
if ( (*it).first == x )
{
// JOL: g++ does not compile correctly:
// return std::make_pair( it, ++it );
it_end = it; ++it_end;
return std::make_pair( it, it_end );
}
else if ( (*it).first > x ) return std::make_pair( it, it );
}
return std::make_pair( it_end, it_end );
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
std::pair< typename DGtal::LabelledMap< TData, L, TWord, N, M >::ConstIterator, typename DGtal::LabelledMap< TData, L, TWord, N, M >::ConstIterator > DGtal::LabelledMap< TData, L, TWord, N, M >::equal_range ( const Key x) const
inline

Get range of equal elements.

Returns the bounds of a range that includes all the elements in the container with a key that compares equal to x. Here, the range will include one element at most.

If x does not match any key in the container, the range returned has a length of zero, with both iterators pointing to the element with nearest key greater than x, if any, or to map::end if x is greater than all the elements in the container.

Parameters:
xany key in 0..L-1
Returns:
a pair, where its member pair::first is an iterator to the lower bound of the range with the same value as the one that would be returned by lower_bound(x), and pair::second is an iterator to the upper bound of the range with the same value as the one that would be returned by upper_bound(x).

Definition at line 957 of file LabelledMap.ih.

{
ConstIterator it = begin(), it_end = end();
for ( ; it != it_end; ++it )
{
if ( (*it).first == x ) return std::make_pair( it, ++it );
else if ( (*it).first > x ) return std::make_pair( it, it );
}
return std::make_pair( it_end, it_end );
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
void DGtal::LabelledMap< TData, L, TWord, N, M >::erase ( Iterator  position)
inline

Erases the pair (key,data) pointed by iterator.

Parameters:
positionany valid iterator in the container.

Definition at line 831 of file LabelledMap.ih.

{
Key key = (*position).first;
ASSERT( myLabels.test( key ) );
myLabels.reset( key );
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::SizeType DGtal::LabelledMap< TData, L, TWord, N, M >::erase ( Key  key)
inline

Erases the element of key key.

Parameters:
keyany key (in 0..L-1)
Returns:
the number of elements deleted (0 or 1).

Definition at line 843 of file LabelledMap.ih.

{
if ( myLabels.test( key ) )
{
myLabels.reset( key );
return 1;
}
return 0;
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
void DGtal::LabelledMap< TData, L, TWord, N, M >::erase ( Iterator  first,
Iterator  last 
)
inline

Erases the elements in the range [first,last).

Parameters:
firsta valid iterator.
lasta valid iterator.

NB: to clear the container, prefer clear() instead of erase( begin(), end() ).

See also:
clear

Definition at line 858 of file LabelledMap.ih.

{
for ( ; first != last; ++first )
erase( first );
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::Data & DGtal::LabelledMap< TData, L, TWord, N, M >::fastAt ( const Key key)
inline

A read-write accessor to the data associated to an existing key.

Parameters:
keyany label (such that count(key)==1)
Returns:
a reference to the associated data.

Definition at line 820 of file LabelledMap.ih.

{
ASSERT( key < L );
ASSERT( myLabels.test( key ) );
return blockAt( myLabels.index( key ) );
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
const DGtal::LabelledMap< TData, L, TWord, N, M >::Data & DGtal::LabelledMap< TData, L, TWord, N, M >::fastAt ( const Key key) const
inline

A read-only accessor to the data associated to an existing key.

Parameters:
keyany label (such that count(key)==1)
Returns:
a const reference to the associated data.

Definition at line 809 of file LabelledMap.ih.

{
ASSERT( key < L );
ASSERT( myLabels.test( key ) );
return blockAt( myLabels.index( key ) );
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::Iterator DGtal::LabelledMap< TData, L, TWord, N, M >::find ( const Key x)
inline

Get iterator to element.

Searches the container for an element with x as key and returns an iterator to it if found, otherwise it returns an iterator to end() (the element past the end of the container).

NB: Another member function, count(), can be used to just check whether a particular key exists. 'count( x ) == 1' is faster than 'find( x ) != end()'.

Parameters:
xKey to be searched for (in 0..L-1)
Returns:
An iterator to the element, if the specified key value is found, end() if the specified key is not found in the container.

Definition at line 972 of file LabelledMap.ih.

{
Iterator it = begin(), it_end = end();
for ( ; it != it_end; ++it )
{
if ( (*it).first == x ) return it;
else if ( (*it).first > x ) return it_end;
}
return it_end;
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::ConstIterator DGtal::LabelledMap< TData, L, TWord, N, M >::find ( const Key x) const
inline

Get iterator to element.

Searches the container for an element with x as key and returns an iterator to it if found, otherwise it returns an iterator to end() (the element past the end of the container).

NB: Another member function, count(), can be used to just check whether a particular key exists. 'count( x ) == 1' is faster than 'find( x ) != end()'.

Parameters:
xKey to be searched for (in 0..L-1)
Returns:
An iterator to the element, if the specified key value is found, end() if the specified key is not found in the container.

Definition at line 987 of file LabelledMap.ih.

{
ConstIterator it = begin(), it_end = end();
for ( ; it != it_end; ++it )
{
if ( (*it).first == x ) return it;
else if ( (*it).first > x ) return it_end;
}
return it_end;
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
std::pair< typename DGtal::LabelledMap< TData, L, TWord, N, M >::Iterator, bool > DGtal::LabelledMap< TData, L, TWord, N, M >::insert ( const Value val)
inline

Insertion of a new data at given label. Follows std::insert return a pair<iterator,bool>). Note that the data is associated to key only if key was not present in the container.

Parameters:
vala pair<key,data>.
Returns:
a pair <iterator,bool> where iterator points on the pair (key,data) while the boolean is true if a new element was indeed created.

NB: This method is provided to follow the std::AssociativeContainer concept. You are discourage to use this functions since the correct iterator must be recomputed at each insert. Prefer operator[] or fastAt.

Definition at line 869 of file LabelledMap.ih.

{
ASSERT( val.first < L );
bool exists = myLabels.test( val.first );
if ( ! exists )
{
unsigned int block_size = size();
myLabels.set( val.first ); // must be done before so that 'index' works.
blockInsert( myLabels.index( val.first ), block_size, val.second );
}
Iterator position = begin();
while ( (*position).first != val.first )
{
// std::cerr << "[" << (*position).first << "]" << std::endl;
++position;
}
return std::make_pair( position, exists );
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::Iterator DGtal::LabelledMap< TData, L, TWord, N, M >::insert ( Iterator  position,
const Value val 
)
inline

Inserts the pair val (key,data) in the container, where position is a hint

Parameters:
positionan iterator used as a hint to find the good place. Unused here.
vala pair (key,data)
Returns:
an iterator on the inserted element.

NB: This method is provided to follow the std::AssociativeContainer concept. You are discourage to use this functions since the correct iterator must be recomputed at each insert. Prefer operator[] or fastAt.

Definition at line 892 of file LabelledMap.ih.

{
ASSERT( val.first < L );
if ( ! myLabels.test( val.first ) )
{
unsigned int block_size = size();
myLabels.set( val.first ); // must be done before so that 'index' works.
blockInsert( myLabels.index( val.first ), block_size, val.second );
}
position = begin();
while ( (*position).first != val.first )
{
//std::cerr << "[" << (*position).first << "]" << std::endl;
++position;
}
return position;
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
template<typename InputIterator >
void DGtal::LabelledMap< TData, L, TWord, N, M >::insert ( InputIterator  first,
InputIterator  last 
)
inline

Insertion from range. Insert all values in the range. Be careful that if a value in the container has the same key as a value in the range, then the mapped data is not changed.

Template Parameters:
InputIteratormodel of boost::InputIterator whose value type is convertible to Value.
Parameters:
firstan iterator on the first value of the range.
lastan iterator after the last value of the range.

Definition at line 915 of file LabelledMap.ih.

{
BOOST_CONCEPT_ASSERT(( boost::InputIterator< InputIterator > ));
for ( ; first != last; ++first )
{
Key k = first->first;
if ( ! myLabels.test( k ) )
{
unsigned int block_size = size();
myLabels.set( k ); // must be done before so that 'index' works.
blockInsert( myLabels.index( k ), block_size, first->second );
}
}
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
bool DGtal::LabelledMap< TData, L, TWord, N, M >::isValid ( ) const
inline

Checks the validity/consistency of the object.

Returns:
'true' if the object is valid, 'false' otherwise.

Definition at line 1202 of file LabelledMap.ih.

{
return true;
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::KeyCompare DGtal::LabelledMap< TData, L, TWord, N, M >::key_comp ( ) const
inline
Returns:
a comparator object for two keys. Corresponds to k1 < k2.

Definition at line 688 of file LabelledMap.ih.

{
return KeyCompare();
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
const DGtal::LabelledMap< TData, L, TWord, N, M >::LabelsType & DGtal::LabelledMap< TData, L, TWord, N, M >::labels ( ) const
inline
Returns:
a reference to the labels.

Definition at line 641 of file LabelledMap.ih.

{
return myLabels;
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::Iterator DGtal::LabelledMap< TData, L, TWord, N, M >::lower_bound ( const Key x)
inline

Return iterator to lower bound.

Returns an iterator pointing to the first element in the container whose key does not compare less than x (using the container's comparison object), i.e. it is either equal or greater.

Unlike upper_bound(), this member function returns an iterator to the element also if it compares equal to x and not only if it compares greater.

Notice that, internally, all the elements in this container are always ordered by their keys, therefore all the elements that follow the one returned by this function will have a key that compares greater than x.

Parameters:
xKey to be searched for (in 0..L-1)
Returns:
an iterator to the the first element in the container whose key does not compare less than x.

Definition at line 1002 of file LabelledMap.ih.

{
Iterator it = begin(), it_end = end();
for ( ; it != it_end; ++it )
{
if ( (*it).first >= x ) return it;
}
return it_end;
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::ConstIterator DGtal::LabelledMap< TData, L, TWord, N, M >::lower_bound ( const Key x) const
inline

Return iterator to lower bound.

Returns an iterator pointing to the first element in the container whose key does not compare less than x, i.e. it is either equal or greater.

Unlike upper_bound(), this member function returns an iterator to the element also if it compares equal to x and not only if it compares greater.

Notice that, internally, all the elements in this container are always ordered by their keys, therefore all the elements that follow the one returned by this function will have a key that compares greater than x.

Parameters:
xKey to be searched for (in 0..L-1)
Returns:
an iterator to the the first element in the container whose key does not compare less than x.

Definition at line 1016 of file LabelledMap.ih.

{
ConstIterator it = begin(), it_end = end();
for ( ; it != it_end; ++it )
{
if ( (*it).first >= x ) return it;
}
return it_end;
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::SizeType DGtal::LabelledMap< TData, L, TWord, N, M >::max_size ( ) const
inline

The maximum number of datas storable in the structure.

Definition at line 668 of file LabelledMap.ih.

{
return L; //SizeType( -1 ) / (2*sizeof( Data ));
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M > & DGtal::LabelledMap< TData, L, TWord, N, M >::operator= ( const LabelledMap< TData, L, TWord, N, M > &  other)
inline

Assignment.

Parameters:
otherthe object to copy.
Returns:
a reference on 'this'.

Definition at line 586 of file LabelledMap.ih.

References DGtal::LabelledMap< TData, L, TWord, N, M >::__FirstBlock::data, DGtal::LabelledMap< TData, L, TWord, N, M >::myFirstBlock, DGtal::LabelledMap< TData, L, TWord, N, M >::myLabels, DGtal::LabelledMap< TData, L, TWord, N, M >::DataOrBlockPointer::nextBlock, and DGtal::LabelledMap< TData, L, TWord, N, M >::size().

{
if ( this != &other )
{
myLabels = other.myLabels;
unsigned int theSize = other.size();
myFirstBlock = other.myFirstBlock;
// there is one more stored data in the last block.
unsigned int s = N + 1;
const __AnyBlock* nextBlock = other.myFirstBlock.data.nextBlock;
__AnyBlock** currentPointer = & myFirstBlock.data.nextBlock;
while ( s < theSize )
{
*currentPointer = new __AnyBlock( *nextBlock );
s += M;
currentPointer = & ( (*currentPointer)->next );
}
}
return *this;
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::Data & DGtal::LabelledMap< TData, L, TWord, N, M >::operator[] ( const Key key)
inline

Follows std::operator[]. Given a key key, returns a reference to the associated data.

Parameters:
keyany label
Returns:
a reference to the associated data.

Definition at line 789 of file LabelledMap.ih.

{
ASSERT( key < L );
bool exists = myLabels.test( key );
if ( ! exists )
{
unsigned int block_size = size();
myLabels.set( key ); // must be done before so that 'index' works.
return blockInsert( myLabels.index( key ), block_size, Data() );
}
else
{
return blockAt( myLabels.index( key ) );
}
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
const DGtal::LabelledMap< TData, L, TWord, N, M >::Data & DGtal::LabelledMap< TData, L, TWord, N, M >::operator[] ( const Key key) const
inline

Read-only version. Follows std::operator[]. Given a key key, returns a reference to the associated data.

Parameters:
keyany label
Returns:
a const reference to the associated data.

Definition at line 769 of file LabelledMap.ih.

{
ASSERT( key < L );
bool exists = myLabels.test( key );
if ( ! exists )
{
unsigned int block_size = size();
myLabels.set( key ); // must be done before so that 'index' works.
return blockInsert( myLabels.index( key ), block_size, Data() );
}
else
{
return blockAt( myLabels.index( key ) );
}
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
void DGtal::LabelledMap< TData, L, TWord, N, M >::selfDisplay ( std::ostream &  out) const
inline

Writes/Displays the object on an output stream.

Parameters:
outthe output stream where the object is written.

Definition at line 1162 of file LabelledMap.ih.

{
if ( size() == 0 ) out << "()";
else
{
ConstIterator it = begin();
ConstIterator it_end = end();
out << "( ";
out << "(" << (*it).first << "," << (*it).second << ")";
++it;
for ( ; it != it_end; ++it )
{
out << ",(" << (*it).first << "," << (*it).second << ")";
}
out << " )";
}
// {
// BlockConstIterator it = blockBegin();
// BlockConstIterator it_end = blockEnd();
// BlockConstIterator it_last = it;
// out << "(";
// out << *it;
// ++it;
// for ( ; it != it_end; ++it )
// {
// out << ( ( it_last.myDatas == it.myDatas ) ? ',' : ';' );
// out << *it;
// it_last = it;
// }
// out << ")";
// }
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::SizeType DGtal::LabelledMap< TData, L, TWord, N, M >::size ( ) const
inline
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
void DGtal::LabelledMap< TData, L, TWord, N, M >::swap ( Self other)
inline

Swap content. Exchanges the content of the container with the content of mp, which is another map object containing elements of the same type. Sizes may differ.

After the call to this member function, the elements in this container are those which were in mp before the call, and the elements of mp are those which were in this.

NB: not exactly standard ! The iterators pointing on the first block change roles ! The other references and pointers remain valid for the swapped objects.

Definition at line 706 of file LabelledMap.ih.

References DGtal::LabelledMap< TData, L, TWord, N, M >::myFirstBlock, and DGtal::LabelledMap< TData, L, TWord, N, M >::myLabels.

{
std::swap( myFirstBlock, other.myFirstBlock );
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::Iterator DGtal::LabelledMap< TData, L, TWord, N, M >::upper_bound ( const Key x)
inline

Return iterator to upper bound.

Returns an iterator pointing to the first element in the container whose key compares greater than x. (>x)

Unlike lower_bound(), this member function does not return an iterator to the element if its key compares equal to x, but only if it compares strictly greater.

Notice that, internally, all the elements in this container are always ordered by their keys, therefore all the elements that follow the one returned by this function will have a key that compares greater than x.

Parameters:
xKey to be searched for (in 0..L-1)
Returns:
an iterator to the the first element in the container whose key compares greater than x.

Definition at line 1030 of file LabelledMap.ih.

{
Iterator it = begin(), it_end = end();
for ( ; it != it_end; ++it )
{
if ( (*it).first > x ) return it;
}
return it_end;
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::ConstIterator DGtal::LabelledMap< TData, L, TWord, N, M >::upper_bound ( const Key x) const
inline

Return iterator to upper bound.

Returns an iterator pointing to the first element in the container whose key compares greater than x. (>x)

Unlike lower_bound(), this member function does not return an iterator to the element if its key compares equal to x, but only if it compares strictly greater.

Notice that, internally, all the elements in this container are always ordered by their keys, therefore all the elements that follow the one returned by this function will have a key that compares greater than x.

Parameters:
xKey to be searched for (in 0..L-1)
Returns:
an iterator to the the first element in the container whose key compares greater than x.

Definition at line 1044 of file LabelledMap.ih.

{
ConstIterator it = begin(), it_end = end();
for ( ; it != it_end; ++it )
{
if ( (*it).first > x ) return it;
}
return it_end;
}
template<typename TData , unsigned int L, typename TWord , unsigned int N, unsigned int M>
DGtal::LabelledMap< TData, L, TWord, N, M >::ValueCompare DGtal::LabelledMap< TData, L, TWord, N, M >::value_comp ( ) const
inline
Returns:
a comparator object for two values. Corresponds to v1.first < v2.first.

Definition at line 697 of file LabelledMap.ih.

{
return ValueCompare();
}

Field Documentation

template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
__FirstBlock DGtal::LabelledMap< TData, L, TWord, N, M >::myFirstBlock
private
template<typename TData, unsigned int L, typename TWord, unsigned int N, unsigned int M>
LabelsType DGtal::LabelledMap< TData, L, TWord, N, M >::myLabels
private

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