Go to the documentation of this file.
28 template<
class T, Foam::label Offset>
31 if( (i < 0) || (i >= nextFree_) )
35 "void Foam::LongList<T, label>::"
36 "checkIndex(const label i) const"
37 ) <<
"Index " << i <<
" is not in range " << 0
42 template<
class T, Foam::label Offset>
45 unsigned int t =
sizeof(
T);
59 template<
class T, Foam::label Offset>
71 "template<class T, Foam::label Offset>\n"
72 "inline void Foam::LongList<T, Offset>::allocateSize(const label)"
76 const label numblock1 = ((
s-1)>>shift_) + 1;
77 const label blockSize = 1<<shift_;
79 if( numblock1 < numBlocks_ )
81 for(
label i=numblock1;i<numBlocks_;++i)
82 delete [] dataPtr_[i];
84 else if( numblock1 > numBlocks_ )
86 if( numblock1 >= numAllocatedBlocks_ )
90 numAllocatedBlocks_ += 64;
91 }
while( numblock1 > numAllocatedBlocks_ );
93 T** dataptr1 =
new T*[numAllocatedBlocks_];
95 for(
label i=0;i<numBlocks_;++i)
96 dataptr1[i] = dataPtr_[i];
103 for(
label i=numBlocks_;i<numblock1;++i)
104 dataPtr_[i] =
new T[blockSize];
107 numBlocks_ = numblock1;
108 N_ = numBlocks_ * blockSize;
111 template<
class T, Foam::label Offset>
114 for(
label i=0;i<numBlocks_;++i)
115 delete [] dataPtr_[i];
125 numAllocatedBlocks_ = 0;
132 template<
class T, Foam::label Offset>
138 numAllocatedBlocks_(0),
143 initializeParameters();
147 template<
class T, Foam::label Offset>
153 numAllocatedBlocks_(0),
158 initializeParameters();
164 template<
class T, Foam::label Offset>
170 numAllocatedBlocks_(0),
175 initializeParameters();
180 template<
class T, Foam::label Offset>
186 numAllocatedBlocks_(0),
194 template<
class T, Foam::label Offset>
202 template<
class T, Foam::label Offset>
208 template<
class T, Foam::label Offset>
211 if( !contiguous<T>() )
214 <<
"Cannot return the binary size of a list of "
215 "non-primitive elements"
219 return nextFree_*
sizeof(
T);
222 template<
class T, Foam::label Offset>
229 template<
class T, Foam::label Offset>
236 template<
class T, Foam::label Offset>
244 template<
class T, Foam::label Offset>
264 template<
class T, Foam::label Offset>
267 if( nextFree_ >= N_ )
269 allocateSize(nextFree_+1);
272 operator[](nextFree_++) =
e;
275 template<
class T, Foam::label Offset>
282 template<
class T, Foam::label Offset>
285 for(
label i=0;i<nextFree_;++i)
286 if( (*
this)[i] ==
e )
292 template<
class T, Foam::label Offset>
298 for(
label i=0;i<nextFree_;++i)
299 if( (*
this)[i] ==
e )
305 template<
class T, Foam::label Offset>
312 "void Foam::LongList<T, Offset>::remove()"
316 T el = operator[](i);
317 operator[](i) = operator[](nextFree_-1);
322 template<
class T, Foam::label Offset>
329 "void Foam::LongList<T, Offset>::remove()"
333 T lastEl = operator[](nextFree_-1);
341 template<
class T, Foam::label Offset>
348 return dataPtr_[i>>shift_][i&mask_];
351 template<
class T, Foam::label Offset>
358 return dataPtr_[i>>shift_][i&mask_];
361 template<
class T, Foam::label Offset>
367 return operator[](i);
371 template<
class T, Foam::label Offset>
374 return operator()(i);
377 template<
class T, Foam::label Offset>
380 for(
label i=0;i<nextFree_;++i)
384 template<
class T, Foam::label Offset>
390 operator[](i) = l[i];
T & newElmt(const label)
return a non-const access to an element,
points setSize(newPointi)
void initializeParameters()
initialize width and mask
void append(const T &e)
Append an element at the end of the list.
T & operator()(const label)
Return non-const access to an element,.
void clear()
Clear the list, i.e. set next free to zero.
LongList< T, Offset > & shrink()
Shrink the list to the number of elements used.
void clearOut()
delete all elements
label containsAtPosition(const T &e) const
label size() const
Size of the active part of the list.
void checkIndex(const label i) const
check index
label nextFree_
number of elements in the list
void setSize(const label)
Reset size of List.
label N_
number of allocated elements
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
void transfer(LongList< T, Offset > &)
transfer the list from another one without allocating it
const T & operator[](const label i) const
get and set operators
LongList()
Construct null.
void operator=(const T &)
Assignment of all entries to the given value.
errorManip< error > abort(error &err)
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
label numBlocks_
number of used blocks of data
T remove(const label i)
Return and remove the element.
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
void appendIfNotIn(const T &e)
label byteSize() const
Return the binary size in number of characters of the UList.
Template function to specify if the data of a type are contiguous.
bool contains(const T &e) const
check if the element is in the list (takes linear time)
const dimensionedScalar e
Elementary charge.
void allocateSize(const label)
Allocate memory for the list.
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
T ** dataPtr_
array of pointers to the blocks of data, each of the size WIDTH
label numAllocatedBlocks_