31 #if defined(IndexedListWithBlocks_RECURSES)
32 #error Recursive header files inclusion detected in IndexedListWithBlocks.h
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 );
722 template <
typename TValue,
unsigned int N,
unsigned int M>
732 #include "DGtal/base/IndexedListWithBlocks.ih"
739 #undef IndexedListWithBlocks_RECURSES
bool operator!=(const Self &other) const
ConstIterator(const ConstIterator &other)
std::forward_iterator_tag iterator_category
Self & operator+=(DifferenceType n)
Pointer operator->() const
DifferenceType difference_type
ConstIterator(const FirstBlock &block, unsigned int idx)
std::ptrdiff_t DifferenceType
only positive offsets allowed.
const AnyBlock * myNext
pointer to next block or 0 if last block.
Self & operator=(const Self &other)
bool operator==(const Self &other) const
const Value * myValues
array of myNbValues values.
unsigned int myIdx
current index in myValues of the iterator
unsigned int myNbValues
number of valid values in array myValues
Reference operator*() const
Reference operator[](DifferenceType n) const
unsigned int myIdx
current index in myValues of the iterator
std::forward_iterator_tag iterator_category
DifferenceType difference_type
Value * myValues
array of myNbValues values.
Self & operator=(const Self &other)
AnyBlock * myNext
pointer to next block or 0 if last block.
bool operator==(const Self &other) const
Iterator(const Iterator &other)
std::ptrdiff_t DifferenceType
only positive offsets allowed.
unsigned int myNbValues
number of valid values in array myValues
Pointer operator->() const
Reference operator*() const
Self & operator+=(DifferenceType n)
Iterator(FirstBlock &block, unsigned int idx)
Reference operator[](DifferenceType n) const
bool operator!=(const Self &other) const
Aim: Represents a mixed list/array structure which is useful in some context. It is essentially a lis...
void insert(unsigned int idx, const Value &value)
BOOST_STATIC_ASSERT(N >=1)
Value & operator[](unsigned int idx)
SizeType max_size() const
IndexedListWithBlocks & operator=(const IndexedListWithBlocks &other)
void erase(unsigned int idx)
const Value & ConstReference
ConstReference const_reference
const Value & operator[](unsigned int idx) const
ConstPointer const_pointer
std::ptrdiff_t DifferenceType
DifferenceType difference_type
BOOST_STATIC_ASSERT(M >=2)
IndexedListWithBlocks(const IndexedListWithBlocks &other)
ConstIterator begin() const
ConstIterator const_iterator
ConstIterator end() const
SizeType capacity() const
void selfDisplay(std::ostream &out) const
const Value * ConstPointer
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
AnyBlock * erase(unsigned int idx, unsigned int size)
void insert(unsigned int idx, unsigned int size, const Value &v)
void erase(unsigned int idx)
void insert(unsigned int idx, const Value &v)
Used in blocks to finish it or to point to the next block.