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; }
185 Data &
insert(
unsigned int idx,
unsigned int size,
const Data & v )
187 ASSERT( idx <= size );
190 std::copy_backward( datas + idx, datas + size, datas + size + 1 );
191 return ( datas[ idx ] = v );
193 else if ( size == N )
197 data.lastData = datas[ N - 1 ];
198 std::copy_backward( datas + idx, datas + N - 1, datas + N );
199 return ( datas[ idx ] = v );
203 return ( data.lastData = v );
206 else if ( size == (N+1) )
213 next->
datas[ 0 ] = datas[ N - 1 ];
214 next->
datas[ 1 ] = data.lastData;
215 std::copy_backward( datas + idx, datas + N - 1, datas + N );
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 );
236 Data v1 = datas[ N - 1 ];
237 std::copy_backward( datas + idx, datas + N - 1, datas + N );
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 ) )
257 std::copy( datas + idx + 1, datas + size, datas + idx );
260 else if ( size == N + 2 )
264 std::copy( datas + idx + 1, datas + N, datas + idx );
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;
287 std::copy( datas + idx + 1, datas + N, datas + idx );
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 );
306 Data &
insert(
unsigned int idx,
unsigned int size,
const Data & v )
308 ASSERT( idx <= size );
316 return ( next->datas[ 0 ] = v );
321 return next->insert( idx - M, size - M, v );
326 if ( size <= ( M - 1) )
329 std::copy_backward( datas + idx, datas + size,
331 return ( datas[ idx ] = v );
335 Data v1 = datas[ M - 1 ];
336 std::copy_backward( datas + idx, datas + M - 1, datas + M );
343 next->
datas[ 0 ] = v1;
348 next->insert( 0, size - M, v1 );
351 return ( datas[ idx ] = v );
371 std::copy( datas + idx + 1, datas + M, datas + idx );
375 datas[ M - 1 ] = next->datas[ 0 ];
376 next = next->erase( 0, size - M );
380 next = next->erase( idx - M, size - M );
460 Pointer operator->()
const;
472 Self operator++(
int );
479 Self& operator+=( DifferenceType n );
486 Reference
operator[]( DifferenceType n )
const;
493 bool operator==(
const Self & other )
const;
500 bool operator!=(
const Self & other )
const;
578 Pointer operator->()
const;
590 Self operator++(
int );
597 Self& operator+=( DifferenceType n );
604 Reference
operator[]( DifferenceType n )
const;
611 bool operator==(
const Self & other )
const;
618 bool operator!=(
const Self & other )
const;
696 Pointer operator->()
const;
708 Self operator++(
int );
715 bool operator==(
const Self & other )
const;
722 bool operator!=(
const Self & other )
const;
725 Data & _data()
const;
726 const Data & _const_data()
const;
744 inline bool operator()(
const Value & v1,
const Value & v2 )
const 746 return v1.first < v2.first;
774 template <
typename InputIterator>
775 LabelledMap( InputIterator first, InputIterator last );
795 const LabelsType &
labels()
const;
800 SizeType
size()
const;
840 void swap( Self & other );
853 SizeType
count(
const Key & key )
const;
871 const Data &
operator[](
const Key & key )
const;
879 Data &
fastAt(
const Key & key );
887 const Data &
fastAt(
const Key & key )
const;
905 std::pair<Iterator, bool>
insert(
const Value & val );
920 Iterator
insert( Iterator position,
const Value & val );
933 template <
typename InputIterator>
934 void insert( InputIterator first, InputIterator last );
941 void erase( Iterator position );
949 SizeType
erase( Key key );
960 void erase( Iterator first, Iterator last );
995 std::pair<Iterator, Iterator>
equal_range(
const Key & x );
1018 std::pair<ConstIterator, ConstIterator>
equal_range(
const Key & x )
const;
1037 Iterator
find (
const Key & x );
1163 Data &
blockAt(
unsigned int idx );
1172 const Data &
blockAt(
unsigned int idx )
const;
1184 Data &
blockInsert(
unsigned int idx,
unsigned int block_size,
const Data & data );
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 )
1278 : _p( p ), _q( q ), _sL( sL ), _sV( sV ), _sP( sP ), _sA( sA )
1282 double fctNM(
unsigned int N,
unsigned int M )
const 1284 double alpha0 = _sL + _sV * ( N+1 );
1285 double beta0 = _sV * M + _sA + _sP;
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 );
1295 double beta0 = _sV * M + _sA + _sP;
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)
std::pair< const Key, Data > Value
LabelsType::ConstIterator LabelsConstIterator
BlockConstIterator myBlockIt
ConstIterator to visit datas.
std::forward_iterator_tag iterator_category
void blockErase(unsigned int idx)
__FirstBlock myFirstBlock
MyDigitalSurface::ConstIterator ConstIterator
ValueCompare value_compare
std::forward_iterator_tag iterator_category
Value comparator class. Always natural ordering between keys.
Aim: Represents a map label -> data, where the label is an integer between 0 and a constant L-1...
LabelledMap & operator=(const LabelledMap &other)
ConstIterator end() const
Data & insert(unsigned int idx, unsigned int size, const Data &v)
Data & insert(unsigned int idx, unsigned int size, const Data &v)
bool operator()(Key k1, Key k2) const
ConstEnumerator ConstIterator
std::forward_iterator_tag iterator_category
double fctNMpq(unsigned int N, unsigned int M, double p, double q) const
bool operator()(const Value &v1, const Value &v2) const
SizeType count(const Key &key) const
std::ptrdiff_t DifferenceType
void erase(Iterator position)
const Value * ConstPointer
Data & fastAt(const Key &key)
BlockIterator blockBegin()
std::pair< Iterator, Iterator > equal_range(const Key &x)
const Value & ConstReference
const __AnyBlock * myNext
pointer to next block or 0 if last block.
Data * myDatas
array of myNbDatas datas.
Key comparator class. Always natural ordering.
ConstReference const_reference
Iterator lower_bound(const Key &x)
LabelledMapMemFunctor(double p, double q, unsigned int sL, unsigned int sV, unsigned int sP, unsigned int sA)
double fctNM(unsigned int N, unsigned int M) const
ConstIterator const_iterator
void selfDisplay(std::ostream &out) const
std::ptrdiff_t DifferenceType
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
void erase(unsigned int idx, unsigned int size)
unsigned int myIdx
current index in myDatas of the iterator
KeyCompare key_comp() const
unsigned int myIdx
current index in myDatas of the iterator
std::pair< Iterator, bool > insert(const Value &val)
LabelsType myLabels
Stores the labels for this sequence of datas.
LabelledMap< TData, L, TWord, N, M > Self
Data & blockAt(unsigned int idx)
Used in first block to finish it or to point to the next block.
BOOST_STATIC_ASSERT(L >=1)
DGtal is the top-level namespace which contains all DGtal functions and types.
SizeType capacity() const
DifferenceType difference_type
__AnyBlock * erase(unsigned int idx, unsigned int size)
Value Reference
Note the trick here. The reference is a rvalue. Works only for const iterator.
__AnyBlock * myNext
pointer to next block or 0 if last block.
unsigned int myNbDatas
number of valid datas in array myDatas
ConstIterator begin() const
SizeType max_size() const
Iterator upper_bound(const Key &x)
Key key_type
Forward declaration.
const Data * myDatas
array of myNbDatas datas.
std::ptrdiff_t DifferenceType
only positive offsets allowed.
const LabelsType & labels() const
DifferenceType difference_type
Iterator find(const Key &x)
Data & blockInsert(unsigned int idx, unsigned int block_size, const Data &data)
ConstIterator Iterator
non-mutable class via iterators.
ConstPointer const_pointer
LabelsConstIterator myLabelsIt
ConstIterator to visit keys.
std::ptrdiff_t DifferenceType
only positive offsets allowed.
DifferenceType difference_type
KForm< Calculus, order, duality > operator*(const typename Calculus::Scalar &scalar, const KForm< Calculus, order, duality > &form)
void blockClear(unsigned int size)
DifferenceType difference_type
unsigned int myNbDatas
number of valid datas in array myDatas
ValueCompare value_comp() const
std::pair< unsigned int, unsigned int > argminLabelledMapMemoryUsageForGeometricDistribution(unsigned int L, double prob_no_data, double prob_one_data)
Data & operator[](const Key &key)
Labels< L, Word > LabelsType