DGtal 1.3.0
Loading...
Searching...
No Matches
Public Member Functions | Data Fields
DGtal::IndexedListWithBlocks< TValue, N, M >::FirstBlock Struct Reference

#include <DGtal/base/IndexedListWithBlocks.h>

Public Member Functions

 FirstBlock ()
 
void insert (unsigned int idx, const Value &v)
 
void erase (unsigned int idx)
 

Data Fields

unsigned int size
 
Value values [N]
 
ValueOrBlockPointer data
 

Detailed Description

template<typename TValue, unsigned int N, unsigned int M>
struct DGtal::IndexedListWithBlocks< TValue, N, M >::FirstBlock

Represents the first block in the container. Internal structure.

Definition at line 137 of file IndexedListWithBlocks.h.

Constructor & Destructor Documentation

◆ FirstBlock()

template<typename TValue , unsigned int N, unsigned int M>
DGtal::IndexedListWithBlocks< TValue, N, M >::FirstBlock::FirstBlock ( )
inline

Definition at line 139 of file IndexedListWithBlocks.h.

139 : size( 0 )
140 { data.nextBlock = 0; }

Member Function Documentation

◆ erase()

template<typename TValue , unsigned int N, unsigned int M>
void DGtal::IndexedListWithBlocks< TValue, N, M >::FirstBlock::erase ( unsigned int  idx)
inline

Definition at line 193 of file IndexedListWithBlocks.h.

194 {
195 // std::cerr << "FirstBlock::erase(" << idx << ")"
196 // << " this=" << this
197 // << " next=" << data.nextBlock
198 // << std::endl;
199 ASSERT( idx < size );
200 if ( size <= ( N + 1 ) )
201 {
202 // works also in the case we use 'data' to store a N+1-th value.
203 std::copy( values + idx + 1, values + size, values + idx );
204 data.nextBlock = 0;
205 }
206 else if ( size == N + 2 )
207 {
208 if ( idx < N )
209 {
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;
215 }
216 else if ( idx == N )
217 {
218 Value tmp = data.nextBlock->values[ 1 ];
219 delete data.nextBlock;
220 data.lastValue = tmp;
221 }
222 else // idx == N + 1
223 {
224 Value tmp = data.nextBlock->values[ 0 ];
225 delete data.nextBlock;
226 data.lastValue = tmp;
227 }
228 }
229 else // size > N + 2
230 {
231 if ( idx < N )
232 {
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 );
236 }
237 else
238 data.nextBlock = data.nextBlock->erase( idx - N, size - N );
239 }
240 --size;
241 }

References DGtal::IndexedListWithBlocks< TValue, N, M >::FirstBlock::size.

◆ insert()

template<typename TValue , unsigned int N, unsigned int M>
void DGtal::IndexedListWithBlocks< TValue, N, M >::FirstBlock::insert ( unsigned int  idx,
const Value v 
)
inline

Definition at line 143 of file IndexedListWithBlocks.h.

144 {
145 if ( size <= N )
146 {
147 ASSERT( idx <= size );
148 // works also in the case we use 'data' to store a N+1-th value.
149 std::copy_backward( values + idx, values + size, values + size + 1 );
150 values[ idx ] = v;
151 }
152 else if ( size == (N+1) )
153 {
154 ASSERT( idx <= size );
155 // This cannot be tested.
156 // ASSERT( data.nextBlock == 0 );
157 AnyBlock* next = new AnyBlock;
158 if ( idx < N )
159 {
160 next->values[ 0 ] = values[ N - 1 ];
161 next->values[ 1 ] = data.lastValue;
162 std::copy_backward( values + idx, values + N - 1, values + N );
163 values[ idx ] = v;
164 }
165 else if ( idx == N )
166 {
167 next->values[ 0 ] = v;
168 next->values[ 1 ] = data.lastValue;
169 }
170 else if ( idx > N )
171 {
172 next->values[ 0 ] = data.lastValue;
173 next->values[ 1 ] = v;
174 }
175 data.nextBlock = next;
176 }
177 else // size > N + 1
178 {
179 if ( idx < N )
180 {
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 );
184 values[ idx ] = v;
185 }
186 else
187 data.nextBlock->insert( idx - N, size - N, v );
188 }
189 ++size;
190 }

References DGtal::IndexedListWithBlocks< TValue, N, M >::FirstBlock::size, and DGtal::IndexedListWithBlocks< TValue, N, M >::AnyBlock::values.

Field Documentation

◆ data

template<typename TValue , unsigned int N, unsigned int M>
ValueOrBlockPointer DGtal::IndexedListWithBlocks< TValue, N, M >::FirstBlock::data

Definition at line 245 of file IndexedListWithBlocks.h.

◆ size

template<typename TValue , unsigned int N, unsigned int M>
unsigned int DGtal::IndexedListWithBlocks< TValue, N, M >::FirstBlock::size

◆ values

template<typename TValue , unsigned int N, unsigned int M>
Value DGtal::IndexedListWithBlocks< TValue, N, M >::FirstBlock::values[N]

Definition at line 244 of file IndexedListWithBlocks.h.


The documentation for this struct was generated from the following file: