Commit b92ed1ec authored by Mark Olesen's avatar Mark Olesen
Browse files

DynamicList - fixed setSize() semantics

setSize(const label)
  - When the new size is smaller than the addressed list size, the addressed
    list size is reduced and the allocated size does not change.
  - Otherwise the allocated size is adjusted, but the addressed list size
    does not change.

setSize(const label, const T&)
  - When the new size is larger than the addressed list size, both allocated
    and addressed list sizes are adjusted.

NOTE: it might be more consistent to have setSize(label) also adjust the
      addressed list size.  This also corresponds to what previous releases
      did, although I don't know if anyone has relied upon any particular
      behaviour
parent 8aa36e10
......@@ -84,7 +84,6 @@ class DynamicList
//- Allocated size for underlying List.
label allocSize_;
public:
// Related types
......@@ -117,10 +116,17 @@ public:
// Edit
//- Reset size of List.
//- Alter the list size.
// When the new size is smaller than the addressed list size,
// the addressed list size is reduced and the allocated size
// does not change.
// Otherwise the allocated size is adjusted, but the
// addressed list size does not change.
inline void setSize(const label);
//- Reset size of List and value for new elements.
//- Alter the list size and assign a value for new elements.
// If the new size is larger than the addressed list size,
// both allocated and addressed list sizes are adjusted.
inline void setSize(const label, const T&);
//- Clear the list, i.e. set the size to zero.
......
......@@ -81,12 +81,12 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::setSize
{
if (s <= List<T>::size())
{
// shrink addressable size, leave allocated size untouched
// adjust addressed size, leave allocated size untouched
List<T>::size(s);
}
else if (s > allocSize_)
else
{
// increase allocated size, leave addressable size untouched
// adjust allocated size, leave addressed size untouched
label nextFree = List<T>::size();
allocSize_ = s;
List<T>::setSize(allocSize_);
......@@ -104,27 +104,16 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::setSize
{
if (s <= List<T>::size())
{
// shrink addressable size, leave allocated size untouched
// shrink addressed size, leave allocated size untouched
List<T>::size(s);
}
else if (s > allocSize_)
else
{
// increase allocated size, leave addressable size untouched
// fill in newly allocated values with constant value
label nextFree = List<T>::size();
// increase allocated size and fill previously unused elements
// with constant value.
// The addressed size now matches the allocated size
allocSize_ = s;
List<T>::setSize(allocSize_, t);
List<T>::size(nextFree);
}
else
{
// leave allocated and addressable sizes untouched
// fill in new exposed values with constant value
label nextFree = List<T>::size();
while (nextFree < s)
{
this->operator[](nextFree++) = t;
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment