31 #if defined(LabelledMap_RECURSES)
32 #error Recursive header files inclusion detected in LabelledMap.h
33 #else // defined(LabelledMap_RECURSES)
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(
unsigned int idx,
unsigned int 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"
1339 #endif // !defined LabelledMap_h
1341 #undef LabelledMap_RECURSES
1342 #endif // else defined(LabelledMap_RECURSES)
DifferenceType difference_type
Self & operator+=(DifferenceType n)
bool operator()(Key k1, Key k2) const
Data & blockInsert(size_t idx, size_t block_size, const Data &data)
unsigned int myNbDatas
number of valid datas in array myDatas
Self & operator+=(DifferenceType n)
MyDigitalSurface::ConstIterator ConstIterator
SizeType count(const Key &key) const
std::pair< ConstIterator, ConstIterator > equal_range(const Key &x) const
BlockIterator(const BlockIterator &other)
ConstIterator lower_bound(const Key &x) const
const LabelsType & labels() const
const Data * myDatas
array of myNbDatas datas.
const Data & fastAt(const Key &key) const
LabelledMap & operator=(const LabelledMap &other)
const Value & ConstReference
unsigned int myIdx
current index in myDatas of the iterator
Iterator upper_bound(const Key &x)
std::ptrdiff_t DifferenceType
ConstIterator end() const
bool operator==(const Self &other) const
ConstIterator find(const Key &x) const
__AnyBlock * myNext
pointer to next block or 0 if last block.
Labels< L, Word > LabelsType
Reference operator*() const
Value Reference
Note the trick here. The reference is a rvalue. Works only for const iterator.
BlockConstIterator blockBegin() const
BlockConstIterator(const __FirstBlock &block, unsigned int idx, unsigned int size)
void blockClear(size_t size)
const Data & _const_data() const
void insert(InputIterator first, InputIterator last)
Data & fastAt(const Key &key)
BOOST_STATIC_ASSERT(M >=2)
std::pair< Iterator, bool > insert(const Value &val)
LabelledMap(const LabelledMap &other)
KeyCompare key_comp() const
BlockIterator(__FirstBlock &block, unsigned int idx, unsigned int size)
bool operator!=(const Self &other) const
BOOST_STATIC_ASSERT(L >=1)
Pointer operator->() const
double fctNMpq(unsigned int N, unsigned int M, double p, double q) const
LabelsType::ConstIterator LabelsConstIterator
__AnyBlock * erase(unsigned int idx, unsigned int size)
Reference operator[](DifferenceType n) const
BlockConstIterator blockEnd() const
Reference operator*() const
LabelledMapMemFunctor(double p, double q, unsigned int sL, unsigned int sV, unsigned int sP, unsigned int sA)
Reference operator*() const
Data & insert(unsigned int idx, unsigned int size, const Data &v)
Data & blockAt(size_t idx)
std::ptrdiff_t DifferenceType
void erase(Iterator position)
Pointer operator->() const
DifferenceType difference_type
DGtal is the top-level namespace which contains all DGtal functions and types.
ConstReference const_reference
BlockConstIterator myBlockIt
ConstIterator to visit datas.
Iterator insert(Iterator position, const Value &val)
BOOST_STATIC_ASSERT(N >=0)
double fctNM(unsigned int N, unsigned int M) const
ConstEnumerator ConstIterator
ValueCompare value_compare
LabelsConstIterator myLabelsIt
ConstIterator to visit keys.
Self & operator=(const Self &other)
ConstIterator(LabelsConstIterator lIt, BlockConstIterator bIt)
ConstIterator(const ConstIterator &other)
Aim: Represents a map label -> data, where the label is an integer between 0 and a constant L-1....
ConstIterator begin() const
std::pair< Iterator, Iterator > equal_range(const Key &x)
Key comparator class. Always natural ordering.
bool operator!=(const Self &other) const
bool operator!=(const Self &other) const
std::forward_iterator_tag iterator_category
DifferenceType difference_type
LabelsType myLabels
Stores the labels for this sequence of datas.
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
std::forward_iterator_tag iterator_category
const Value * ConstPointer
SizeType capacity() const
Value comparator class. Always natural ordering between keys.
ConstPointer const_pointer
Self & operator=(const Self &other)
bool operator()(const Value &v1, const Value &v2) const
Self & operator=(const Self &other)
const __AnyBlock * myNext
pointer to next block or 0 if last block.
Data * myDatas
array of myNbDatas datas.
Iterator lower_bound(const Key &x)
Pointer operator->() const
ConstIterator upper_bound(const Key &x) const
bool operator==(const Self &other) const
Data & operator[](const Key &key)
std::pair< const Key, Data > Value
Used in first block to finish it or to point to the next block.
ValueCompare value_comp() const
Data & insert(unsigned int idx, unsigned int size, const Data &v)
BlockIterator blockBegin()
void selfDisplay(std::ostream &out) const
void erase(Iterator first, Iterator last)
const Data & operator[](const Key &key) const
unsigned int myNbDatas
number of valid datas in array myDatas
DifferenceType difference_type
LabelledMap< TData, L, TWord, N, M > Self
bool operator==(const Self &other) const
Iterator find(const Key &x)
LabelledMap(InputIterator first, InputIterator last)
void erase(unsigned int idx, unsigned int size)
__FirstBlock myFirstBlock
const Data & blockAt(size_t idx) const
ConstIterator const_iterator
void blockErase(size_t idx)
SizeType max_size() const
unsigned int myIdx
current index in myDatas of the iterator
std::forward_iterator_tag iterator_category
BlockConstIterator(const BlockConstIterator &other)
Reference operator[](DifferenceType n) const
std::ptrdiff_t DifferenceType
only positive offsets allowed.
ConstIterator Iterator
non-mutable class via iterators.
Key key_type
Forward declaration.
std::ptrdiff_t DifferenceType
only positive offsets allowed.
std::pair< unsigned int, unsigned int > argminLabelledMapMemoryUsageForGeometricDistribution(unsigned int L, double prob_no_data, double prob_one_data)