diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H index a5fe88bd50..20f9258bda 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H @@ -117,14 +117,14 @@ public: //- Construct null inline DynamicList(); - //- Construct given size. + //- Construct an empty list with given reserve size. explicit inline DynamicList(const label nElem); //- Construct with given size and value for all elements. inline DynamicList(const label nElem, const T& val); //- Construct with given size initializing all elements to zero - inline DynamicList(const label s, const zero); + inline DynamicList(const label nElem, const zero); //- Copy construct. inline DynamicList(const DynamicList& lst); @@ -174,10 +174,14 @@ public: // Member Functions - // Access + // Access + + //- Normal lower capacity limit - the SizeMin template parameter + inline label min_size() const; + + //- Size of the underlying storage. + inline label capacity() const; - //- Size of the underlying storage. - inline label capacity() const; // Edit @@ -311,7 +315,7 @@ public: //- Return non-const access to an element, resizing list if // necessary - inline T& operator()(const label elemI); + inline T& operator()(const label i); //- Assignment of all addressed entries to the given value inline void operator=(const T& val); diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H index 2fcfc66062..c6adaec88f 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H @@ -63,17 +63,11 @@ inline Foam::DynamicList::DynamicList() template -inline Foam::DynamicList::DynamicList -( - const label nElem -) +inline Foam::DynamicList::DynamicList(const label nElem) : - List(nElem), - capacity_(nElem) + capacity_(0) { - // We could also enforce sizing granularity - - List::size(0); + reserve(nElem); } @@ -85,7 +79,7 @@ inline Foam::DynamicList::DynamicList ) : List(nElem, val), - capacity_(nElem) + capacity_(List::size()) {} @@ -97,7 +91,7 @@ inline Foam::DynamicList::DynamicList ) : List(nElem, Zero), - capacity_(nElem) + capacity_(List::size()) {} @@ -108,7 +102,7 @@ inline Foam::DynamicList::DynamicList ) : List(lst), - capacity_(lst.size()) + capacity_(List::size()) {} @@ -120,7 +114,7 @@ inline Foam::DynamicList::DynamicList ) : List(lst), - capacity_(lst.size()) + capacity_(List::size()) {} @@ -131,7 +125,7 @@ inline Foam::DynamicList::DynamicList ) : List(lst), - capacity_(lst.size()) + capacity_(List::size()) {} @@ -157,7 +151,7 @@ inline Foam::DynamicList::DynamicList ) : List(begIter, endIter), - capacity_(this->size()) + capacity_(List::size()) {} @@ -168,7 +162,7 @@ inline Foam::DynamicList::DynamicList ) : List(lst), - capacity_(lst.size()) + capacity_(List::size()) {} @@ -179,7 +173,7 @@ inline Foam::DynamicList::DynamicList ) : List(lst), - capacity_(lst.size()) + capacity_(List::size()) {} @@ -234,8 +228,14 @@ inline Foam::DynamicList::DynamicList // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -inline Foam::label Foam::DynamicList::capacity() -const +inline Foam::label Foam::DynamicList::min_size() const +{ + return SizeMin; +} + + +template +inline Foam::label Foam::DynamicList::capacity() const { return capacity_; } @@ -730,15 +730,15 @@ inline Foam::label Foam::DynamicList::subset template inline T& Foam::DynamicList::operator() ( - const label elemI + const label i ) { - if (elemI >= List::size()) + if (i >= List::size()) { - setSize(elemI + 1); + setSize(i + 1); } - return this->operator[](elemI); + return this->operator[](i); } diff --git a/src/OpenFOAM/containers/Lists/List/List.H b/src/OpenFOAM/containers/Lists/List/List.H index d4ff38d488..aaacbda88b 100644 --- a/src/OpenFOAM/containers/Lists/List/List.H +++ b/src/OpenFOAM/containers/Lists/List/List.H @@ -111,13 +111,6 @@ class List ); -protected: - - //- Override size to be inconsistent with allocated storage. - // Use with care - inline void size(const label n); - - public: // Static Member Functions @@ -211,10 +204,6 @@ public: // Member Functions - //- Return the number of elements in the UList - inline label size() const; - - // Edit //- Alias for setSize(const label) diff --git a/src/OpenFOAM/containers/Lists/List/ListI.H b/src/OpenFOAM/containers/Lists/List/ListI.H index d3549e131b..f93a099bb4 100644 --- a/src/OpenFOAM/containers/Lists/List/ListI.H +++ b/src/OpenFOAM/containers/Lists/List/ListI.H @@ -151,29 +151,17 @@ inline void Foam::List::resize(const label newSize, const T& val) template inline T& Foam::List::newElmt(const label i) { - if (i >= this->size()) + const label n = this->size(); + + if (i >= n) { - setSize(2*this->size()); + setSize(2*n); } return UList::operator[](i); } -template -inline void Foam::List::size(const label n) -{ - UList::size_ = n; -} - - -template -inline Foam::label Foam::List::size() const -{ - return UList::size_; -} - - template inline Foam::Xfer> Foam::List::xfer() { @@ -184,7 +172,7 @@ inline Foam::Xfer> Foam::List::xfer() template inline void Foam::List::append(const T& val) { - setSize(size()+1, val); + setSize(this->size()+1, val); } @@ -200,9 +188,9 @@ inline void Foam::List::append(const UList& lst) label nextFree = this->size(); setSize(nextFree + lst.size()); - forAll(lst, elemI) + forAll(lst, i) { - this->operator[](nextFree++) = lst[elemI]; + this->operator[](nextFree++) = lst[i]; } } @@ -213,9 +201,9 @@ inline void Foam::List::append(const UIndirectList& lst) label nextFree = this->size(); setSize(nextFree + lst.size()); - forAll(lst, elemI) + forAll(lst, i) { - this->operator[](nextFree++) = lst[elemI]; + this->operator[](nextFree++) = lst[i]; } } diff --git a/src/OpenFOAM/containers/Lists/UList/UList.H b/src/OpenFOAM/containers/Lists/UList/UList.H index 23fee6ab04..5c7999e229 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.H +++ b/src/OpenFOAM/containers/Lists/UList/UList.H @@ -102,6 +102,10 @@ protected: // Protected Member Functions + //- Override size to be inconsistent with allocated storage. + // Use with care + inline void size(const label n); + //- Write the UList with its compound type void writeEntry(Ostream& os) const; @@ -465,7 +469,7 @@ public: friend Ostream& operator<< ( Ostream& os, - const UList& L + const UList& lst ); //- Read List contents from Istream. diff --git a/src/OpenFOAM/containers/Lists/UList/UListI.H b/src/OpenFOAM/containers/Lists/UList/UListI.H index 36c74ee28b..e8060ac9bd 100644 --- a/src/OpenFOAM/containers/Lists/UList/UListI.H +++ b/src/OpenFOAM/containers/Lists/UList/UListI.H @@ -327,6 +327,14 @@ Foam::UList::crend() const return &v_[-1]; } + +template +inline void Foam::UList::size(const label n) +{ + size_ = n; +} + + template inline Foam::label Foam::UList::size() const { diff --git a/src/OpenFOAM/containers/Lists/UList/UListIO.C b/src/OpenFOAM/containers/Lists/UList/UListIO.C index 08d1856917..e6f9a97ad5 100644 --- a/src/OpenFOAM/containers/Lists/UList/UListIO.C +++ b/src/OpenFOAM/containers/Lists/UList/UListIO.C @@ -164,9 +164,9 @@ Foam::Ostream& Foam::UList::writeList // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * // template -Foam::Ostream& Foam::operator<<(Foam::Ostream& os, const Foam::UList& L) +Foam::Ostream& Foam::operator<<(Ostream& os, const UList& lst) { - return L.writeList(os, 10); + return lst.writeList(os, 10); } diff --git a/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H b/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H index ea2f2a7e5b..1d99fcb6b6 100644 --- a/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H +++ b/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H @@ -199,6 +199,10 @@ public: //- Clear the list and delete storage. inline void clearStorage(); + //- Expand the addressable size to fit the allocated capacity. + // Returns the previous addressable size. + inline label expandStorage(); + //- Shrink the allocated space to the number of elements used. // Returns a reference to the DynamicField. inline DynamicField& shrink(); @@ -222,7 +226,7 @@ public: //- Return non-const access to an element, resizing list if // necessary - inline T& operator()(const label elemI); + inline T& operator()(const label i); //- Assignment of all addressed entries to the given value inline void operator=(const T& val); diff --git a/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H b/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H index 658c0b9d1c..782e2c90ee 100644 --- a/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H +++ b/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H @@ -310,6 +310,18 @@ inline void Foam::DynamicField::clearStorage() } +template +inline Foam::label Foam::DynamicField::expandStorage() +{ + const label nextFree = Field::size(); + + // Allow addressing into the entire list + Field::size(capacity_); + + return nextFree; +} + + template inline Foam::DynamicField& Foam::DynamicField::shrink() @@ -317,10 +329,10 @@ Foam::DynamicField::shrink() label nextFree = Field::size(); if (capacity_ > nextFree) { - // use the full list when resizing + // Use the full list when resizing Field::size(capacity_); - // the new size + // The new size capacity_ = nextFree; Field::setSize(capacity_); Field::size(nextFree); @@ -368,9 +380,9 @@ Foam::DynamicField::append label nextFree = List::size(); setSize(nextFree + lst.size()); - forAll(lst, elemI) + forAll(lst, i) { - this->operator[](nextFree++) = lst[elemI]; + this->operator[](nextFree++) = lst[i]; } return *this; } @@ -401,15 +413,15 @@ inline T Foam::DynamicField::remove() template inline T& Foam::DynamicField::operator() ( - const label elemI + const label i ) { - if (elemI >= Field::size()) + if (i >= Field::size()) { - setSize(elemI + 1); + setSize(i + 1); } - return this->operator[](elemI); + return this->operator[](i); }