31 #if defined(IndexedListWithBlocks_RECURSES) 32 #error Recursive header files inclusion detected in IndexedListWithBlocks.h 33 #else // defined(IndexedListWithBlocks_RECURSES) 35 #define IndexedListWithBlocks_RECURSES 37 #if !defined IndexedListWithBlocks_h 39 #define IndexedListWithBlocks_h 45 #include "DGtal/base/Common.h" 92 template <
typename TValue,
unsigned int N,
unsigned int M>
140 { data.nextBlock = 0; }
143 void insert(
unsigned int idx,
const Value & v )
147 ASSERT( idx <= size );
149 std::copy_backward( values + idx, values + size, values + size + 1 );
152 else if ( size == (N+1) )
154 ASSERT( idx <= size );
160 next->
values[ 0 ] = values[ N - 1 ];
161 next->
values[ 1 ] = data.lastValue;
162 std::copy_backward( values + idx, values + N - 1, values + N );
168 next->
values[ 1 ] = data.lastValue;
172 next->
values[ 0 ] = data.lastValue;
175 data.nextBlock = next;
181 Value v1 = values[ N - 1 ];
182 std::copy_backward( values + idx, values + N - 1, values + N );
183 data.nextBlock->insert( 0, size - N, v1 );
187 data.nextBlock->insert( idx - N, size - N, v );
199 ASSERT( idx < size );
200 if ( size <= ( N + 1 ) )
203 std::copy( values + idx + 1, values + size, values + idx );
206 else if ( size == N + 2 )
210 std::copy( values + idx + 1, values + N, values + idx );
211 values[ N - 1 ] = data.nextBlock->values[ 0 ];
212 Value tmp = data.nextBlock->values[ 1 ];
213 delete data.nextBlock;
214 data.lastValue = tmp;
218 Value tmp = data.nextBlock->values[ 1 ];
219 delete data.nextBlock;
220 data.lastValue = tmp;
224 Value tmp = data.nextBlock->values[ 0 ];
225 delete data.nextBlock;
226 data.lastValue = tmp;
233 std::copy( values + idx + 1, values + N, values + idx );
234 values[ N - 1 ] = data.nextBlock->values[ 0 ];
235 data.nextBlock = data.nextBlock->erase( 0, size - N );
238 data.nextBlock = data.nextBlock->erase( idx - N, size - N );
254 void insert(
unsigned int idx,
unsigned int size,
const Value & v )
256 ASSERT( idx <= size );
266 next->insert( idx - M, size - M, v );
270 if ( size < ( M - 1) )
272 std::copy_backward( values + idx, values + size,
278 Value v1 = values[ M - 1 ];
279 std::copy_backward( values + idx, values + M - 1, values + M );
290 next->insert( 0, size - M, v1 );
311 std::copy( values + idx + 1, values + M, values + idx );
315 values[ M - 1 ] = next->values[ 0 ];
316 next = next->erase( 0, size - M );
320 next = next->erase( idx - M, size - M );
400 Pointer operator->()
const;
412 Self operator++(
int );
419 Self& operator+=( DifferenceType n );
426 Reference
operator[]( DifferenceType n )
const;
433 bool operator==(
const Self & other )
const;
440 bool operator!=(
const Self & other )
const;
518 Pointer operator->()
const;
530 Self operator++(
int );
537 Self& operator+=( DifferenceType n );
544 Reference
operator[]( DifferenceType n )
const;
551 bool operator==(
const Self & other )
const;
558 bool operator!=(
const Self & other )
const;
596 SizeType
size()
const;
635 const Value &
operator[](
unsigned int idx )
const;
646 void insert(
unsigned int idx,
const Value & value );
655 void erase(
unsigned int idx );
722 template <
typename TValue,
unsigned int N,
unsigned int M>
732 #include "DGtal/base/IndexedListWithBlocks.ih" 737 #endif // !defined IndexedListWithBlocks_h 739 #undef IndexedListWithBlocks_RECURSES 740 #endif // else defined(IndexedListWithBlocks_RECURSES) void insert(unsigned int idx, const Value &v)
std::ptrdiff_t DifferenceType
only positive offsets allowed.
MyDigitalSurface::ConstIterator ConstIterator
SizeType capacity() const
unsigned int myNbValues
number of valid values in array myValues
unsigned int myIdx
current index in myValues of the iterator
AnyBlock * myNext
pointer to next block or 0 if last block.
void insert(unsigned int idx, unsigned int size, const Value &v)
const Value * myValues
array of myNbValues values.
AnyBlock * erase(unsigned int idx, unsigned int size)
ConstReference const_reference
std::forward_iterator_tag iterator_category
std::ptrdiff_t DifferenceType
only positive offsets allowed.
void erase(unsigned int idx)
unsigned int myNbValues
number of valid values in array myValues
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
const Value * ConstPointer
IndexedListWithBlocks & operator=(const IndexedListWithBlocks &other)
void selfDisplay(std::ostream &out) const
SizeType max_size() const
Value * myValues
array of myNbValues values.
ConstPointer const_pointer
DifferenceType difference_type
BOOST_STATIC_ASSERT(N >=1)
DGtal is the top-level namespace which contains all DGtal functions and types.
ConstIterator const_iterator
std::forward_iterator_tag iterator_category
std::ptrdiff_t DifferenceType
Used in blocks to finish it or to point to the next block.
void erase(unsigned int idx)
DifferenceType difference_type
const Value & ConstReference
Aim: Represents a mixed list/array structure which is useful in some context. It is essentially a lis...
Value & operator[](unsigned int idx)
const AnyBlock * myNext
pointer to next block or 0 if last block.
KForm< Calculus, order, duality > operator*(const typename Calculus::Scalar &scalar, const KForm< Calculus, order, duality > &form)
DifferenceType difference_type
unsigned int myIdx
current index in myValues of the iterator
void insert(unsigned int idx, const Value &value)