From dd54aa3018360c59d9e6acf8dc870d3befe1296c Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Fri, 26 May 2017 21:02:28 +0200
Subject: [PATCH] BUG: non-lazy PackedList (fixes #484)

- The unset() method never auto-vivifies, whereas the set() method
  always auto-vivifies. In the case where set() is called with a zero
  for its argument - eg, set(index, 0) - this should behave
  identically to an unset() and not auto-vivify out-of-range entries.
---
 .../test/PackedList2/Test-PackedList2.C       |  59 ++--
 .../Lists/PackedList/PackedBoolList.C         |   2 +-
 .../Lists/PackedList/PackedBoolList.H         | 182 +++++------
 .../Lists/PackedList/PackedBoolListI.H        |   2 +-
 .../containers/Lists/PackedList/PackedList.H  | 292 +++++++++---------
 .../containers/Lists/PackedList/PackedListI.H |  10 +-
 6 files changed, 279 insertions(+), 268 deletions(-)

diff --git a/applications/test/PackedList2/Test-PackedList2.C b/applications/test/PackedList2/Test-PackedList2.C
index 2926118ff93..26981b484ff 100644
--- a/applications/test/PackedList2/Test-PackedList2.C
+++ b/applications/test/PackedList2/Test-PackedList2.C
@@ -84,6 +84,12 @@ int main(int argc, char *argv[])
         packed.resize(n, 1);
     }
     Info<< "resize/shrink/resize:" << timer.cpuTimeIncrement() << " s\n\n";
+    Info<< "packed bool size=" << packed.size() << nl;
+
+    // Neither of these should affect the size
+    packed.unset(2*n-1);
+    packed.set(2*n-1, 0);
+    Info<< "packed bool size=" << packed.size() << nl;
 
     // set every other bit on:
     Info<< "set every other bit on and count\n";
@@ -99,8 +105,8 @@ int main(int argc, char *argv[])
         }
     }
     Info<< "Counting brute-force:" << timer.cpuTimeIncrement()
-        << " s" << endl;
-    Info<< "  sum " << sum << endl;
+        << " s" << nl
+        << "  sum " << sum << endl;
 
 
     // Count packed
@@ -110,8 +116,8 @@ int main(int argc, char *argv[])
         sum += packed.count();
     }
     Info<< "Counting via count():" << timer.cpuTimeIncrement()
-        << " s" << endl;
-    Info<< "  sum " << sum << endl;
+        << " s" << nl
+        << "  sum " << sum << endl;
 
 
     // Dummy addition
@@ -123,8 +129,8 @@ int main(int argc, char *argv[])
             sum += i + 1;
         }
     }
-    Info<< "Dummy loop:" << timer.cpuTimeIncrement() << " s" << endl;
-    Info<< "  sum " << sum << endl;
+    Info<< "Dummy loop:" << timer.cpuTimeIncrement() << " s" << nl
+        << "  sum " << sum << " (sum is meaningless)" << endl;
 
     //
     // Read
@@ -139,8 +145,8 @@ int main(int argc, char *argv[])
             sum += stlVector[i];
         }
     }
-    Info<< "Reading stl:" << timer.cpuTimeIncrement() << " s" << endl;
-    Info<< "  sum " << sum << endl;
+    Info<< "Reading stl:" << timer.cpuTimeIncrement() << " s" << nl
+        << "  sum " << sum << endl;
 
 
     // Read unpacked
@@ -152,8 +158,8 @@ int main(int argc, char *argv[])
             sum += unpacked[i];
         }
     }
-    Info<< "Reading unpacked:" << timer.cpuTimeIncrement() << " s" << endl;
-    Info<< "  sum " << sum << endl;
+    Info<< "Reading unpacked:" << timer.cpuTimeIncrement() << " s" << nl
+        << "  sum " << sum << endl;
 
 
     // Read packed
@@ -166,8 +172,8 @@ int main(int argc, char *argv[])
         }
     }
     Info<< "Reading packed using get:" << timer.cpuTimeIncrement()
-        << " s" << endl;
-    Info<< "  sum " << sum << endl;
+        << " s" << nl
+        << "  sum " << sum << endl;
 
 
     // Read packed
@@ -180,8 +186,8 @@ int main(int argc, char *argv[])
         }
     }
     Info<< "Reading packed using reference:" << timer.cpuTimeIncrement()
-        << " s" << endl;
-    Info<< "  sum " << sum << endl;
+        << " s" << nl
+        << "  sum " << sum << endl;
 
 
     // Read via iterator
@@ -194,8 +200,8 @@ int main(int argc, char *argv[])
         }
     }
     Info<< "Reading packed using iterator:" << timer.cpuTimeIncrement()
-        << " s" << endl;
-    Info<< "  sum " << sum << endl;
+        << " s" << nl
+        << "  sum " << sum << endl;
 
 
     // Read via iterator
@@ -208,8 +214,8 @@ int main(int argc, char *argv[])
         }
     }
     Info<< "Reading packed using const_iterator():" << timer.cpuTimeIncrement()
-        << " s" << endl;
-    Info<< "  sum " << sum << endl;
+        << " s" << nl
+        << "  sum " << sum << endl;
 
 
     // Read empty hash
@@ -222,8 +228,8 @@ int main(int argc, char *argv[])
         }
     }
     Info<< "Reading empty labelHashSet:" << timer.cpuTimeIncrement()
-        << " s" << endl;
-    Info<< "  sum " << sum << endl;
+        << " s" << nl
+        << "  sum " << sum << endl;
 
 
     // Read full hash
@@ -236,8 +242,8 @@ int main(int argc, char *argv[])
         }
     }
     Info<< "Reading full labelHashSet:" << timer.cpuTimeIncrement()
-        << " s" << endl;
-    Info<< "  sum " << sum << endl;
+        << " s" << nl
+        << "  sum " << sum << endl;
 
 
     // Read empty static hash
@@ -250,8 +256,8 @@ int main(int argc, char *argv[])
         }
     }
     Info<< "Reading empty StaticHash:" << timer.cpuTimeIncrement()
-        << " s" << endl;
-    Info<< "  sum " << sum << endl;
+        << " s" << nl
+        << "  sum " << sum << endl;
 
 #if 0
     // we can skip this test - it is usually quite slow
@@ -265,8 +271,8 @@ int main(int argc, char *argv[])
         }
     }
     Info<< "Reading full StaticHash:" << timer.cpuTimeIncrement()
-        << " s" << endl;
-    Info<< "  sum " << sum << endl;
+        << " s" << nl
+        << "  sum " << sum << endl;
 #endif
 
     Info<< "Starting write tests" << endl;
@@ -319,7 +325,6 @@ int main(int argc, char *argv[])
     Info<< "Writing packed using set:" << timer.cpuTimeIncrement()
         << " s" << endl;
 
-
     // Write packed
     for (label iter = 0; iter < nIters; ++iter)
     {
diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedBoolList.C b/src/OpenFOAM/containers/Lists/PackedList/PackedBoolList.C
index 791d53cc591..4b01a43dd61 100644
--- a/src/OpenFOAM/containers/Lists/PackedList/PackedBoolList.C
+++ b/src/OpenFOAM/containers/Lists/PackedList/PackedBoolList.C
@@ -286,7 +286,7 @@ Foam::Xfer<Foam::labelList> Foam::PackedBoolList::used() const
 
 // * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * * //
 
-void Foam::PackedBoolList::operator=(const Foam::UList<bool>& lst)
+void Foam::PackedBoolList::operator=(const UList<bool>& lst)
 {
     this->setSize(lst.size());
 
diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedBoolList.H b/src/OpenFOAM/containers/Lists/PackedList/PackedBoolList.H
index b2ca0037f85..f98545a9bd6 100644
--- a/src/OpenFOAM/containers/Lists/PackedList/PackedBoolList.H
+++ b/src/OpenFOAM/containers/Lists/PackedList/PackedBoolList.H
@@ -94,7 +94,7 @@ public:
         inline PackedBoolList();
 
         //- Construct from Istream
-        PackedBoolList(Istream&);
+        PackedBoolList(Istream& is);
 
         //- Construct with given size, initializes list to 0
         explicit inline PackedBoolList(const label size);
@@ -103,19 +103,19 @@ public:
         inline PackedBoolList(const label size, const bool val);
 
         //- Copy constructor
-        inline PackedBoolList(const PackedBoolList&);
+        inline PackedBoolList(const PackedBoolList& lst);
 
         //- Copy constructor
-        explicit inline PackedBoolList(const PackedList<1>&);
+        explicit inline PackedBoolList(const PackedList<1>& lst);
 
         //- Construct by transferring the parameter contents
-        inline PackedBoolList(const Xfer<PackedBoolList>&);
+        inline PackedBoolList(const Xfer<PackedBoolList>& lst);
 
         //- Construct by transferring the parameter contents
-        inline PackedBoolList(const Xfer<PackedList<1>>&);
+        inline PackedBoolList(const Xfer<PackedList<1>>& lst);
 
         //- Construct from a list of bools
-        explicit inline PackedBoolList(const Foam::UList<bool>&);
+        explicit inline PackedBoolList(const UList<bool>& lst);
 
         //- Construct from a list of labels
         //  using the labels as indices to indicate which bits are set
@@ -131,132 +131,132 @@ public:
 
     // Member Functions
 
-        // Access
+      // Access
 
-            using PackedList<1>::set;
-            using PackedList<1>::unset;
+        using PackedList<1>::set;
+        using PackedList<1>::unset;
 
-            //- Set specified bits.
-            void set(const PackedList<1>&);
+        //- Set specified bits.
+        void set(const PackedList<1>& lst);
 
-            //- Set the listed indices. Return number of elements changed.
-            //  Does auto-vivify for non-existent entries.
-            label set(const labelUList& indices);
+        //- Set the listed indices. Return number of elements changed.
+        //  Does auto-vivify for non-existent entries.
+        label set(const labelUList& indices);
 
-            //- Set the listed indices. Return number of elements changed.
-            //  Does auto-vivify for non-existent entries.
-            label set(const UIndirectList<label>& indices);
+        //- Set the listed indices. Return number of elements changed.
+        //  Does auto-vivify for non-existent entries.
+        label set(const UIndirectList<label>& indices);
 
-            //- Unset specified bits.
-            void unset(const PackedList<1>&);
+        //- Unset specified bits.
+        void unset(const PackedList<1>& lst);
 
-            //- Unset the listed indices. Return number of elements changed.
-            //  Never auto-vivify entries.
-            label unset(const labelUList& indices);
+        //- Unset the listed indices. Return number of elements changed.
+        //  Never auto-vivify entries.
+        label unset(const labelUList& indices);
 
-            //- Unset the listed indices. Return number of elements changed.
-            //  Never auto-vivify entries.
-            label unset(const UIndirectList<label>& indices);
+        //- Unset the listed indices. Return number of elements changed.
+        //  Never auto-vivify entries.
+        label unset(const UIndirectList<label>& indices);
 
-            //- Subset with the specified list.
-            void subset(const PackedList<1>&);
+        //- Subset with the specified list.
+        void subset(const PackedList<1>& lst);
 
-            //- Subset with the listed indices.
-            //  Return number of elements subsetted.
-            label subset(const labelUList& indices);
+        //- Subset with the listed indices.
+        //  Return number of elements subsetted.
+        label subset(const labelUList& indices);
 
-            //- Subset with the listed indices.
-            //  Return number of elements subsetted.
-            label subset(const UIndirectList<label>& indices);
+        //- Subset with the listed indices.
+        //  Return number of elements subsetted.
+        label subset(const UIndirectList<label>& indices);
 
 
-            //- Return indices of the used (true) elements as a list of labels
-            Xfer<labelList> used() const;
+        //- Return indices of the used (true) elements as a list of labels
+        Xfer<labelList> used() const;
 
 
-        // Edit
+      // Edit
 
-            //- Transfer the contents of the argument list into this list
-            //  and annul the argument list.
-            inline void transfer(PackedBoolList&);
+        //- Transfer the contents of the argument list into this list
+        //  and annul the argument list.
+        inline void transfer(PackedBoolList& lst);
 
-            //- Transfer the contents of the argument list into this list
-            //  and annul the argument list.
-            inline void transfer(PackedList<1>&);
+        //- Transfer the contents of the argument list into this list
+        //  and annul the argument list.
+        inline void transfer(PackedList<1>& lst);
 
-            //- Transfer contents to the Xfer container
-            inline Xfer<PackedBoolList> xfer();
+        //- Transfer contents to the Xfer container
+        inline Xfer<PackedBoolList> xfer();
 
 
     // Member Operators
 
-            //- Assignment of all entries to the given value.
-            inline void operator=(const bool val);
+        //- Assignment of all entries to the given value.
+        inline void operator=(const bool val);
 
-            //- Assignment operator.
-            inline void operator=(const PackedBoolList&);
+        //- Assignment operator.
+        inline void operator=(const PackedBoolList& lst);
 
-            //- Assignment operator.
-            inline void operator=(const PackedList<1>&);
+        //- Assignment operator.
+        inline void operator=(const PackedList<1>& lst);
 
-            //- Assignment operator.
-            void operator=(const Foam::UList<bool>&);
+        //- Assignment operator.
+        void operator=(const UList<bool>& lst);
 
-            //- Assignment operator,
-            //  using the labels as indices to indicate which bits are set
-            inline void operator=(const labelUList& indices);
+        //- Assignment operator,
+        //  using the labels as indices to indicate which bits are set
+        inline void operator=(const labelUList& indices);
 
-            //- Assignment operator,
-            //  using the labels as indices to indicate which bits are set
-            inline void operator=(const UIndirectList<label>&);
+        //- Assignment operator,
+        //  using the labels as indices to indicate which bits are set
+        inline void operator=(const UIndirectList<label>& indices);
 
-            //- Complement operator
-            inline PackedBoolList operator~() const;
+        //- Complement operator
+        inline PackedBoolList operator~() const;
 
-            //- And operator (lists may be dissimilar sizes)
-            inline PackedBoolList& operator&=(const PackedList<1>&);
+        //- And operator (lists may be dissimilar sizes)
+        inline PackedBoolList& operator&=(const PackedList<1>& lst);
 
-            //- And operator (lists may be dissimilar sizes)
-            //  using the labels as indices to indicate which bits are set
-            inline PackedBoolList& operator&=(const labelUList& indices);
+        //- And operator (lists may be dissimilar sizes)
+        //  using the labels as indices to indicate which bits are set
+        inline PackedBoolList& operator&=(const labelUList& indices);
 
-            //- And operator (lists may be dissimilar sizes)
-            //  using the labels as indices to indicate which bits are set
-            inline PackedBoolList& operator&=(const UIndirectList<label>&);
+        //- And operator (lists may be dissimilar sizes)
+        //  using the labels as indices to indicate which bits are set
+        inline PackedBoolList& operator&=(const UIndirectList<label>& indices);
 
-            //- Xor operator (lists may be dissimilar sizes)
-            //  Retains unique entries
-            PackedBoolList& operator^=(const PackedList<1>&);
+        //- Xor operator (lists may be dissimilar sizes)
+        //  Retains unique entries
+        PackedBoolList& operator^=(const PackedList<1>& lst);
 
-            //- Or operator (lists may be dissimilar sizes)
-            inline PackedBoolList& operator|=(const PackedList<1>&);
+        //- Or operator (lists may be dissimilar sizes)
+        inline PackedBoolList& operator|=(const PackedList<1>& lst);
 
-            //- Or operator (lists may be dissimilar sizes),
-            //  using the labels as indices to indicate which bits are set
-            inline PackedBoolList& operator|=(const labelUList& indices);
+        //- Or operator (lists may be dissimilar sizes),
+        //  using the labels as indices to indicate which bits are set
+        inline PackedBoolList& operator|=(const labelUList& indices);
 
-            //- Or operator (lists may be dissimilar sizes),
-            //  using the labels as indices to indicate which bits are set
-            inline PackedBoolList& operator|=(const UIndirectList<label>&);
+        //- Or operator (lists may be dissimilar sizes),
+        //  using the labels as indices to indicate which bits are set
+        inline PackedBoolList& operator|=(const UIndirectList<label>& indices);
 
 
-            //- Add entries to this list, synonymous with the or operator
-            inline PackedBoolList& operator+=(const PackedList<1>&);
+        //- Add entries to this list, synonymous with the or operator
+        inline PackedBoolList& operator+=(const PackedList<1>& lst);
 
-            //- Add entries to this list, synonymous with the or operator
-            inline PackedBoolList& operator+=(const labelUList& indices);
+        //- Add entries to this list, synonymous with the or operator
+        inline PackedBoolList& operator+=(const labelUList& indices);
 
-            //- Add entries to this list, synonymous with the or operator
-            inline PackedBoolList& operator+=(const UIndirectList<label>&);
+        //- Add entries to this list, synonymous with the or operator
+        inline PackedBoolList& operator+=(const UIndirectList<label>& indices);
 
-            //- Remove entries from this list - unset the specified bits
-            inline PackedBoolList& operator-=(const PackedList<1>&);
+        //- Remove entries from this list - unset the specified bits
+        inline PackedBoolList& operator-=(const PackedList<1>& lst);
 
-            //- Remove entries from this list - unset the specified bits
-            inline PackedBoolList& operator-=(const labelUList& indices);
+        //- Remove entries from this list - unset the specified bits
+        inline PackedBoolList& operator-=(const labelUList& indices);
 
-            //- Remove entries from this list - unset the specified bits
-            inline PackedBoolList& operator-=(const UIndirectList<label>&);
+        //- Remove entries from this list - unset the specified bits
+        inline PackedBoolList& operator-=(const UIndirectList<label>& indices);
 };
 
 
diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedBoolListI.H b/src/OpenFOAM/containers/Lists/PackedList/PackedBoolListI.H
index d5561cfc282..a0702f9a30e 100644
--- a/src/OpenFOAM/containers/Lists/PackedList/PackedBoolListI.H
+++ b/src/OpenFOAM/containers/Lists/PackedList/PackedBoolListI.H
@@ -73,7 +73,7 @@ inline Foam::PackedBoolList::PackedBoolList(const Xfer<PackedList<1>>& lst)
 {}
 
 
-inline Foam::PackedBoolList::PackedBoolList(const Foam::UList<bool>& lst)
+inline Foam::PackedBoolList::PackedBoolList(const UList<bool>& lst)
 :
     PackedList<1>()
 {
diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedList.H b/src/OpenFOAM/containers/Lists/PackedList/PackedList.H
index c07bb1eab11..18720fc2ae9 100644
--- a/src/OpenFOAM/containers/Lists/PackedList/PackedList.H
+++ b/src/OpenFOAM/containers/Lists/PackedList/PackedList.H
@@ -118,9 +118,9 @@ class Ostream;
 template<unsigned nBits> class PackedList;
 
 template<unsigned nBits>
-Istream& operator>>(Istream&, PackedList<nBits>&);
+Istream& operator>>(Istream& is, PackedList<nBits>& lst);
 template<unsigned nBits>
-Ostream& operator<<(Ostream&, const PackedList<nBits>&);
+Ostream& operator<<(Ostream& os, const PackedList<nBits>& lst);
 
 
 /*---------------------------------------------------------------------------*\
@@ -160,11 +160,11 @@ protected:
         inline static label packedLength(const label);
 
         //- Read a list entry (allows for specialization)
-        inline static unsigned int readValue(Istream&);
+        inline static unsigned int readValue(Istream& is);
 
         //- Read an index/value pair and set accordingly.
         //  For bool specialization, read a single index value
-        inline void setPair(Istream&);
+        inline void setPair(Istream& is);
 
 
 private:
@@ -252,167 +252,167 @@ public:
 
     // Member Functions
 
-        // Access
+      // Access
 
-            //- The number of elements that can be stored before reallocating
-            inline label capacity() const;
+        //- The number of elements that can be stored before reallocating
+        inline label capacity() const;
 
-            //- Number of entries.
-            inline label size() const;
+        //- Number of entries.
+        inline label size() const;
 
-            //- Return true if the list is empty (ie, size() is zero).
-            inline bool empty() const;
+        //- Return true if the list is empty (ie, size() is zero).
+        inline bool empty() const;
 
-            //- Get value at index I.
-            //  Never auto-vivify entries.
-            inline unsigned int get(const label i) const;
+        //- Get value at index I.
+        //  Never auto-vivify entries.
+        inline unsigned int get(const label i) const;
 
-            //- Set value at index I. Return true if value changed.
-            //  Does auto-vivify for non-existent entries.
-            //  Default value set is the max_value.
-            inline bool set(const label i, const unsigned int val = ~0u);
+        //- Set value at index I. Return true if value changed.
+        //  Does auto-vivify for non-existent, non-zero entries.
+        //  Default value set is the max_value.
+        inline bool set(const label i, const unsigned int val = ~0u);
 
-            //- Unset the entry at index I. Return true if value changed.
-            //  Never auto-vivify entries.
-            inline bool unset(const label i);
+        //- Unset the entry at index I. Return true if value changed.
+        //  Never auto-vivify entries.
+        inline bool unset(const label i);
 
-            //- Return the underlying packed storage
-            //  Manipulate with utmost caution
-            inline List<unsigned int>& storage();
+        //- Return the underlying packed storage
+        //  Manipulate with utmost caution
+        inline List<unsigned int>& storage();
 
-            //- Return the underlying packed storage
-            inline const List<unsigned int>& storage() const;
+        //- Return the underlying packed storage
+        inline const List<unsigned int>& storage() const;
 
-            //- The list length when packed
-            inline label packedLength() const;
+        //- The list length when packed
+        inline label packedLength() const;
 
-            //- Return the binary size in number of characters
-            //  used in the underlying storage
-            inline std::streamsize byteSize() const;
+        //- Return the binary size in number of characters
+        //  used in the underlying storage
+        inline std::streamsize byteSize() const;
 
-            //- Count number of bits set, O(log(n))
-            //  Uses the Hamming weight (population count) method
-            //  http://en.wikipedia.org/wiki/Hamming_weight
-            unsigned int count() const;
+        //- Count number of bits set, O(log(n))
+        //  Uses the Hamming weight (population count) method
+        //  http://en.wikipedia.org/wiki/Hamming_weight
+        unsigned int count() const;
 
-            //- Return the values as a list of labels
-            Xfer<labelList> values() const;
+        //- Return the values as a list of labels
+        Xfer<labelList> values() const;
 
-            //- Print bit patterns, optionally output unused elements
-            //
-            // addressable bits:
-            //   on: '1', off: '-'
-            //
-            // non-addressable bits:
-            //   on: '!', off: '.'
-            //
-            Ostream& printBits(Ostream&, const bool fullOutput=false) const;
+        //- Print bit patterns, optionally output unused elements
+        //
+        // addressable bits:
+        //   on: '1', off: '-'
+        //
+        // non-addressable bits:
+        //   on: '!', off: '.'
+        //
+        Ostream& printBits(Ostream& os, const bool fullOutput=false) const;
 
-            //- Print information and bit patterns (with printBits)
-            Ostream& printInfo(Ostream&, const bool fullOutput=false) const;
+        //- Print information and bit patterns (with printBits)
+        Ostream& printInfo(Ostream& os, const bool fullOutput=false) const;
 
 
-        // Edit
+      // Edit
 
-            //- Trim any trailing zero elements
-            bool trim();
+        //- Trim any trailing zero elements
+        bool trim();
 
-            //- Invert the bits in the addressable region
-            void flip();
+        //- Invert the bits in the addressable region
+        void flip();
 
-            //- Clear all bits
-            inline void reset();
+        //- Clear all bits
+        inline void reset();
 
-            //- Alter the size of the underlying storage.
-            //  The addressed size will be truncated if needed to fit, but will
-            //  remain otherwise untouched.
-            inline void setCapacity(const label);
+        //- Alter the size of the underlying storage.
+        //  The addressed size will be truncated if needed to fit, but will
+        //  remain otherwise untouched.
+        inline void setCapacity(const label nElem);
 
-            //- Reset addressable list size, does not shrink the allocated size.
-            //  Optionally specify a value for new elements.
-            inline void resize(const label, const unsigned int val = 0u);
+        //- Reset addressable list size, does not shrink the allocated size.
+        //  Optionally specify a value for new elements.
+        inline void resize(const label nElem, const unsigned int val = 0u);
 
-            //- Alias for resize()
-            inline void setSize(const label, const unsigned int val = 0u);
+        //- Alias for resize()
+        inline void setSize(const label nElem, const unsigned int val = 0u);
 
-            //- Reserve allocation space for at least this size.
-            //  Never shrinks the allocated size.
-            //  The list size is adjusted as per DynamicList with
-            //  SizeInc=0, SizeMult=2, SizeDiv=1
-            inline void reserve(const label);
+        //- Reserve allocation space for at least this size.
+        //  Never shrinks the allocated size.
+        //  The list size is adjusted as per DynamicList with
+        //  SizeInc=0, SizeMult=2, SizeDiv=1
+        inline void reserve(const label nElem);
 
-            //- Clear the list, i.e. set addressable size to zero.
-            //  Does not adjust the underlying storage
-            inline void clear();
+        //- Clear the list, i.e. set addressable size to zero.
+        //  Does not adjust the underlying storage
+        inline void clear();
 
-            //- Clear the list and delete storage.
-            inline void clearStorage();
+        //- Clear the list and delete storage.
+        inline void clearStorage();
 
-            //- Shrink the allocated space to what is actually used.
-            inline void shrink();
+        //- Shrink the allocated space to what is actually used.
+        inline void shrink();
 
-            //- Transfer the contents of the argument list into this list
-            //  and annul the argument list.
-            inline void transfer(PackedList<nBits>&);
+        //- Transfer the contents of the argument list into this list
+        //  and annul the argument list.
+        inline void transfer(PackedList<nBits>& lst);
 
-            //- Transfer contents to the Xfer container
-            inline Xfer<PackedList<nBits>> xfer();
+        //- Transfer contents to the Xfer container
+        inline Xfer<PackedList<nBits>> xfer();
 
 
-        // IO
+      // IO
 
-            //- Clear list and read from stream
-            Istream& read(Istream& is);
+        //- Clear list and read from stream
+        Istream& read(Istream& is);
 
-            //- Write the List, with line-breaks in ASCII if the list length
-            //  exceeds shortListLen. Using '0' suppresses line-breaks entirely.
-            //  A special indexed output (ASCII only) is triggered by specifying
-            //  a negative value for shortListLen.
-            //
-            // The indexed output may be convenient in some situations.
-            // The general format is a group of index/value pairs:
-            //  \verbatim
-            //      { (index1 value1) (index2 value2) (index3 value3) }
-            // \endverbatim
-            // The bool specialization just uses the indices corresponding to
-            // non-zero entries instead of a index/value pair:
-            // \verbatim
-            //     { index1 index2 index3 }
-            // \endverbatim
-            Ostream& writeList(Ostream& os, const label shortListLen=0) const;
+        //- Write the List, with line-breaks in ASCII if the list length
+        //  exceeds shortListLen. Using '0' suppresses line-breaks entirely.
+        //  A special indexed output (ASCII only) is triggered by specifying
+        //  a negative value for shortListLen.
+        //
+        // The indexed output may be convenient in some situations.
+        // The general format is a group of index/value pairs:
+        //  \verbatim
+        //      { (index1 value1) (index2 value2) (index3 value3) }
+        // \endverbatim
+        // The bool specialization just uses the indices corresponding to
+        // non-zero entries instead of a index/value pair:
+        // \verbatim
+        //     { index1 index2 index3 }
+        // \endverbatim
+        Ostream& writeList(Ostream& os, const label shortListLen=0) const;
 
-            //- Write as a dictionary entry with keyword
-            void writeEntry(const word& keyword, Ostream& os) const;
+        //- Write as a dictionary entry with keyword
+        void writeEntry(const word& keyword, Ostream& os) const;
 
 
-    // Member operators
+      // Member operators
 
-            //- Append a value at the end of the list
-            inline PackedList<nBits>& append(const unsigned int val);
+        //- Append a value at the end of the list
+        inline PackedList<nBits>& append(const unsigned int val);
 
-            //- Remove and return the last element
-            inline unsigned int remove();
+        //- Remove and return the last element
+        inline unsigned int remove();
 
-            //- Get value at index I
-            //  Never auto-vivify entries.
-            inline unsigned int operator[](const label i) const;
+        //- Get value at index I
+        //  Never auto-vivify entries.
+        inline unsigned int operator[](const label i) const;
 
-            //- Set value at index I.
-            //  Returns iterator to perform the actual operation.
-            //  Does not auto-vivify entries, but will when assigned to.
-            inline iteratorBase operator[](const label i);
+        //- Set value at index I.
+        //  Returns iterator to perform the actual operation.
+        //  Does not auto-vivify entries, but will when assigned to.
+        inline iteratorBase operator[](const label i);
 
-            //- Assignment of all entries to the given value. Takes linear time.
-            inline void operator=(const unsigned int val);
+        //- Assignment of all entries to the given value. Takes linear time.
+        inline void operator=(const unsigned int val);
 
-            //- Assignment operator.
-            void operator=(const PackedList<nBits>& lst);
+        //- Assignment operator.
+        void operator=(const PackedList<nBits>& lst);
 
-            //- Assignment operator.
-            void operator=(const labelUList& lst);
+        //- Assignment operator.
+        void operator=(const labelUList& lst);
 
-            //- Assignment operator.
-            void operator=(const UIndirectList<label>& lst);
+        //- Assignment operator.
+        void operator=(const UIndirectList<label>& lst);
 
 
     // Iterators and helpers
@@ -442,7 +442,7 @@ public:
                 inline unsigned int get() const;
 
                 //- Set value, returning true if changed, no range-checking
-                inline bool set(unsigned int);
+                inline bool set(unsigned int val);
 
 
             // Constructors
@@ -451,7 +451,7 @@ public:
                 inline iteratorBase();
 
                 //- Construct from base list and position index
-                inline iteratorBase(const PackedList*, const label);
+                inline iteratorBase(const PackedList* lst, const label i);
 
 
         public:
@@ -463,17 +463,17 @@ public:
 
                 //- Write index/value for a non-zero entry
                 //  The bool specialization writes the index only
-                inline bool writeIfSet(Ostream&) const;
+                inline bool writeIfSet(Ostream& os) const;
 
             // Member Operators
 
                 //- Compare values (not positions)
-                inline bool operator==(const iteratorBase&) const;
-                inline bool operator!=(const iteratorBase&) const;
+                inline bool operator==(const iteratorBase& iter) const;
+                inline bool operator!=(const iteratorBase& iter) const;
 
                 //- Assign value, not position.
                 //  This allows packed[0] = packed[3] for assigning values
-                inline void operator=(const iteratorBase&);
+                inline void operator=(const iteratorBase& iter);
 
                 //- Assign value.
                 //  A non-existent entry will be auto-vivified.
@@ -484,7 +484,7 @@ public:
                 inline operator unsigned int () const;
 
             //- Print information and values
-            Ostream& printInfo(Ostream&) const;
+            Ostream& printInfo(Ostream& os) const;
         };
 
 
@@ -496,11 +496,11 @@ public:
 
             //- Disallow copy constructor from const_iterator
             //  This would violate const-ness!
-            iterator(const const_iterator&);
+            iterator(const const_iterator& iter);
 
             //- Disallow assignment from const_iterator
             //  This would violate const-ness!
-            void operator=(const const_iterator&);
+            void operator=(const const_iterator& iter);
 
 
         public:
@@ -513,21 +513,21 @@ public:
                 //- Construct from iterator base, eg iter(packedlist[i])
                 //  but also  "iterator iter = packedlist[i];"
                 //  An out-of-range iterator is assigned end()
-                inline iterator(const iteratorBase&);
+                inline iterator(const iteratorBase& iter);
 
                 //- Construct from base list and position index
-                inline iterator(const PackedList*, const label);
+                inline iterator(const PackedList* lst, const label i);
 
 
             // Member Operators
 
                 //- Compare positions (not values)
-                inline bool operator==(const iteratorBase&) const;
-                inline bool operator!=(const iteratorBase&) const;
+                inline bool operator==(const iteratorBase& iter) const;
+                inline bool operator!=(const iteratorBase& iter) const;
 
                 //- Assign from iteratorBase, eg iter = packedlist[i]
                 //  An out-of-range iterator is assigned end()
-                inline void operator=(const iteratorBase&);
+                inline void operator=(const iteratorBase& iter);
 
                 //- Return value
                 inline unsigned int operator*() const;
@@ -571,24 +571,24 @@ public:
                 //- Construct from iterator base, eg iter(packedlist[i])
                 //  but also  "const_iterator iter = packedlist[i];"
                 //  An out-of-range iterator is assigned cend()
-                inline const_iterator(const iteratorBase&);
+                inline const_iterator(const iteratorBase& iter);
 
                 //- Construct from base list and position index
-                inline const_iterator(const PackedList*, const label);
+                inline const_iterator(const PackedList* lst, const label i);
 
                 //- Construct from iterator
-                inline const_iterator(const iterator&);
+                inline const_iterator(const iterator& iter);
 
 
             // Member operators
 
                 //- Compare positions (not values)
-                inline bool operator==(const iteratorBase&) const;
-                inline bool operator!=(const iteratorBase&) const;
+                inline bool operator==(const iteratorBase& iter) const;
+                inline bool operator!=(const iteratorBase& iter) const;
 
                 //- Assign from iteratorBase or derived
                 //  eg, iter = packedlist[i] or even iter = list.begin()
-                inline void operator=(const iteratorBase&);
+                inline void operator=(const iteratorBase& iter);
 
                 //- Return referenced value directly
                 inline unsigned int operator*() const;
@@ -621,14 +621,14 @@ public:
 
         friend Istream& operator>> <nBits>
         (
-            Istream&,
-            PackedList<nBits>&
+            Istream& is,
+            PackedList<nBits>& lst
         );
 
         friend Ostream& operator<< <nBits>
         (
-            Ostream&,
-            const PackedList<nBits>&
+            Ostream& os,
+            const PackedList<nBits>& lst
         );
 };
 
diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H b/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H
index 7849d5a792d..ad136b903fa 100644
--- a/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H
+++ b/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H
@@ -267,7 +267,7 @@ Foam::PackedList<nBits>::clone() const
 template<unsigned nBits>
 inline Foam::PackedList<nBits>::iteratorBase::iteratorBase()
 :
-    list_(0),
+    list_(nullptr),
     index_(0)
 {}
 
@@ -1002,6 +1002,12 @@ inline bool Foam::PackedList<nBits>::set
     }
     else if (i >= size_)
     {
+        if (!val)
+        {
+            // Same as unset out-of-bounds = noop
+            return false;
+        }
+
         // Lazy evaluation - increase size on assigment
         resize(i + 1);
     }
@@ -1013,7 +1019,7 @@ inline bool Foam::PackedList<nBits>::set
 template<unsigned nBits>
 inline bool Foam::PackedList<nBits>::unset(const label i)
 {
-    // lazy evaluation - ignore out-of-bounds
+    // Unset out-of-bounds = noop
     if (i < 0 || i >= size_)
     {
         return false;
-- 
GitLab