31#if defined(LabelledMap_RECURSES)
32#error Recursive header files inclusion detected in LabelledMap.h
35#define LabelledMap_RECURSES
37#if !defined LabelledMap_h
46#include "DGtal/base/Common.h"
47#include "DGtal/base/Labels.h"
117 template <
typename TData,
unsigned int L,
typename TWord,
118 unsigned int N,
unsigned int M>
132 typedef std::pair<const Key, Data>
Value;
182 { data.nextBlock = 0; }
187 ASSERT( idx <= size );
191 return (
datas[ idx ] = v );
193 else if ( size == N )
197 data.lastData =
datas[ N - 1 ];
199 return (
datas[ idx ] = v );
203 return ( data.lastData = v );
206 else if ( size == (N+1) )
214 next->
datas[ 1 ] = data.lastData;
216 data.nextBlock = next;
217 return (
datas[ idx ] = v );
221 next->
datas[ 1 ] = data.lastData;
222 data.nextBlock = next;
223 return ( next->
datas[ 0 ] = v );
227 next->
datas[ 0 ] = data.lastData;
228 data.nextBlock = next;
229 return ( next->
datas[ 1 ] = v );
238 data.nextBlock->insert( 0, size - N, v1 );
239 return (
datas[ idx ] = v );
242 return data.nextBlock->insert( idx - N, size - N, v );
247 void erase(
size_t idx,
size_t size )
253 ASSERT( idx < size );
254 if ( size <= ( N + 1 ) )
260 else if ( size == N + 2 )
265 datas[ N - 1 ] = data.nextBlock->datas[ 0 ];
266 Data tmp = data.nextBlock->datas[ 1 ];
267 delete data.nextBlock;
272 Data tmp = data.nextBlock->datas[ 1 ];
273 delete data.nextBlock;
278 Data tmp = data.nextBlock->datas[ 0 ];
279 delete data.nextBlock;
288 datas[ N - 1 ] = data.nextBlock->datas[ 0 ];
289 data.nextBlock = data.nextBlock->erase( 0, size - N );
292 data.nextBlock = data.nextBlock->erase( idx - N, size - N );
308 ASSERT( idx <= size );
326 if ( size <= ( M - 1) )
329 std::copy_backward(
datas + idx,
datas + size,
331 return (
datas[ idx ] = v );
351 return (
datas[ idx ] = v );
746 return v1.first < v2.first;
774 template <
typename InputIterator>
933 template <
typename InputIterator>
934 void insert( InputIterator first, InputIterator last );
1256 template <
typename TData,
unsigned int L,
typename TWord,
1257 unsigned int N,
unsigned int M>
1276 unsigned int sL,
unsigned int sV,
1277 unsigned int sP,
unsigned int sA )
1282 double fctNM(
unsigned int N,
unsigned int M )
const
1284 double alpha0 =
_sL +
_sV * ( N+1 );
1287 + beta0 *
_q * pow(1.0 -
_p, (
double)N+1)
1288 * ( 1.0 + pow(1.0 -
_p, (
double)M-1 )
1289 / ( 1.0 - pow(1.0 -
_p, (
double)M ) ) );
1292 double fctNMpq(
unsigned int N,
unsigned int M,
double p,
double q )
const
1294 double alpha0 =
_sL +
_sV * ( N+1 );
1297 + beta0 * q * pow(1.0 - p, (
double)N+1)
1298 * ( 1.0 + pow(1.0 - p, (
double)M-1 )
1299 / ( 1.0 - pow(1.0 - p, (
double)M ) ) );
1323 template <
typename TData>
1324 std::pair< unsigned int, unsigned int >
1326 (
unsigned int L,
double prob_no_data,
double prob_one_data );
1334#include "DGtal/base/LabelledMap.ih"
1341#undef LabelledMap_RECURSES
BlockConstIterator(const __FirstBlock &block, unsigned int idx, unsigned int size)
Reference operator*() const
const __AnyBlock * myNext
pointer to next block or 0 if last block.
unsigned int myNbDatas
number of valid datas in array myDatas
unsigned int myIdx
current index in myDatas of the iterator
const Data * myDatas
array of myNbDatas datas.
DifferenceType difference_type
BlockConstIterator(const BlockConstIterator &other)
Self & operator+=(DifferenceType n)
bool operator!=(const Self &other) const
Self & operator=(const Self &other)
Reference operator[](DifferenceType n) const
bool operator==(const Self &other) const
std::forward_iterator_tag iterator_category
std::ptrdiff_t DifferenceType
only positive offsets allowed.
Pointer operator->() const
std::forward_iterator_tag iterator_category
BlockIterator(__FirstBlock &block, unsigned int idx, unsigned int size)
Reference operator[](DifferenceType n) const
unsigned int myNbDatas
number of valid datas in array myDatas
bool operator!=(const Self &other) const
Self & operator+=(DifferenceType n)
Pointer operator->() const
bool operator==(const Self &other) const
unsigned int myIdx
current index in myDatas of the iterator
std::ptrdiff_t DifferenceType
only positive offsets allowed.
DifferenceType difference_type
Reference operator*() const
Data * myDatas
array of myNbDatas datas.
__AnyBlock * myNext
pointer to next block or 0 if last block.
Self & operator=(const Self &other)
BlockIterator(const BlockIterator &other)
BlockConstIterator myBlockIt
ConstIterator to visit datas.
const Data & _const_data() const
LabelsConstIterator myLabelsIt
ConstIterator to visit keys.
std::ptrdiff_t DifferenceType
Reference operator*() const
Value Reference
Note the trick here. The reference is a rvalue. Works only for const iterator.
DifferenceType difference_type
ConstIterator(const ConstIterator &other)
bool operator==(const Self &other) const
Pointer operator->() const
Self & operator=(const Self &other)
bool operator!=(const Self &other) const
ConstIterator(LabelsConstIterator lIt, BlockConstIterator bIt)
std::forward_iterator_tag iterator_category
Key comparator class. Always natural ordering.
bool operator()(Key k1, Key k2) const
Value comparator class. Always natural ordering between keys.
bool operator()(const Value &v1, const Value &v2) const
Aim: Represents a map label -> data, where the label is an integer between 0 and a constant L-1....
Data & blockAt(size_t idx)
ConstIterator find(const Key &x) const
DifferenceType difference_type
BOOST_STATIC_ASSERT(M >=2)
BlockConstIterator blockEnd() const
ConstIterator upper_bound(const Key &x) const
LabelledMap< TData, L, TWord, N, M > Self
SizeType count(const Key &key) const
LabelledMap(InputIterator first, InputIterator last)
ValueCompare value_compare
const Value & ConstReference
const Data & operator[](const Key &key) const
ValueCompare value_comp() const
void blockErase(size_t idx)
void insert(InputIterator first, InputIterator last)
LabelsType::ConstIterator LabelsConstIterator
Key key_type
Forward declaration.
ConstIterator begin() const
const LabelsType & labels() const
BOOST_STATIC_ASSERT(N >=0)
BlockConstIterator blockBegin() const
ConstPointer const_pointer
Data & blockInsert(size_t idx, size_t block_size, const Data &data)
__FirstBlock myFirstBlock
Iterator find(const Key &x)
LabelledMap(const LabelledMap &other)
ConstReference const_reference
KeyCompare key_comp() const
LabelsType myLabels
Stores the labels for this sequence of datas.
Iterator lower_bound(const Key &x)
std::pair< Iterator, Iterator > equal_range(const Key &x)
const Data & blockAt(size_t idx) const
ConstIterator lower_bound(const Key &x) const
ConstIterator const_iterator
Iterator insert(Iterator position, const Value &val)
void selfDisplay(std::ostream &out) const
LabelledMap & operator=(const LabelledMap &other)
const Data & fastAt(const Key &key) const
void blockClear(size_t size)
BlockIterator blockBegin()
std::ptrdiff_t DifferenceType
ConstIterator Iterator
non-mutable class via iterators.
SizeType max_size() const
BOOST_STATIC_ASSERT(L >=1)
void erase(Iterator first, Iterator last)
ConstIterator end() const
std::pair< const Key, Data > Value
std::pair< Iterator, bool > insert(const Value &val)
Data & operator[](const Key &key)
const Value * ConstPointer
SizeType capacity() const
Labels< L, Word > LabelsType
std::pair< ConstIterator, ConstIterator > equal_range(const Key &x) const
Iterator upper_bound(const Key &x)
Data & fastAt(const Key &key)
void erase(Iterator position)
Aim: Stores a set of labels in {O..L-1} as a sequence of bits.
ConstEnumerator ConstIterator
std::pair< unsigned int, unsigned int > argminLabelledMapMemoryUsageForGeometricDistribution(unsigned int L, double prob_no_data, double prob_one_data)
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
Data & insert(size_t idx, size_t size, const Data &v)
__AnyBlock * erase(size_t idx, size_t size)
Data & insert(size_t idx, size_t size, const Data &v)
void erase(size_t idx, size_t size)
double fctNM(unsigned int N, unsigned int M) const
LabelledMapMemFunctor(double p, double q, unsigned int sL, unsigned int sV, unsigned int sP, unsigned int sA)
double fctNMpq(unsigned int N, unsigned int M, double p, double q) const
Used in first block to finish it or to point to the next block.