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; }
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 );
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 );
311 std::copy( values + idx + 1, values + M, values + idx );
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)
Self & operator=(const Self &other)
const AnyBlock * myNext
pointer to next block or 0 if last block.
DifferenceType difference_type
SizeType max_size() const
Self & operator+=(DifferenceType n)
Pointer operator->() const
AnyBlock * erase(unsigned int idx, unsigned int size)
ConstPointer const_pointer
Reference operator[](DifferenceType n) const
ConstIterator const_iterator
void insert(unsigned int idx, unsigned int size, const Value &v)
Reference operator*() const
Aim: Represents a mixed list/array structure which is useful in some context. It is essentially a lis...
Reference operator[](DifferenceType n) const
void insert(unsigned int idx, const Value &value)
Used in blocks to finish it or to point to the next block.
unsigned int myIdx
current index in myValues of the iterator
IndexedListWithBlocks & operator=(const IndexedListWithBlocks &other)
void erase(unsigned int idx)
const typedef Value * ConstPointer
Reference operator*() const
unsigned int myIdx
current index in myValues of the iterator
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
AnyBlock * myNext
pointer to next block or 0 if last block.
Self & operator+=(DifferenceType n)
const Value * myValues
array of myNbValues values.
unsigned int myNbValues
number of valid values in array myValues
DGtal is the top-level namespace which contains all DGtal functions and types.
std::forward_iterator_tag iterator_category
std::forward_iterator_tag iterator_category
bool operator!=(const Self &other) const
const typedef Value & Reference
Self & operator=(const Self &other)
bool operator==(const Self &other) const
bool operator!=(const Self &other) const
std::ptrdiff_t DifferenceType
DifferenceType difference_type
std::ptrdiff_t DifferenceType
only positive offsets allowed.
ConstReference const_reference
const typedef Value * Pointer
DifferenceType difference_type
void selfDisplay(std::ostream &out) const
Value * myValues
array of myNbValues values.
BOOST_STATIC_ASSERT(N >=1)
unsigned int myNbValues
number of valid values in array myValues
const typedef Value & ConstReference
Pointer operator->() const
std::ptrdiff_t DifferenceType
only positive offsets allowed.
void erase(unsigned int idx)
bool operator==(const Self &other) const
Value & operator[](unsigned int idx)
void insert(unsigned int idx, const Value &v)
SizeType capacity() const