diff --git a/applications/test/bitSet1/Test-bitSet1.C b/applications/test/bitSet1/Test-bitSet1.C index 776cb65699297c3452e024654896ec61879d8de5..7077bcb3711254387730fb05ce21151b42f5d78f 100644 --- a/applications/test/bitSet1/Test-bitSet1.C +++ b/applications/test/bitSet1/Test-bitSet1.C @@ -76,6 +76,9 @@ int main(int argc, char *argv[]) bitSet set2b(set2, labelRange(15, 30)); Info<<"bitSet slice(15,30) :"; report(set2b, true); + Info<< "set1 == set2: " << (set2 == set2b) << nl; + Info<< "set1 != set2: " << (set2 != set2b) << nl; + { FixedList<label, 4> locs({ -1, 3, 4, 12}); diff --git a/src/OpenFOAM/containers/Bits/PackedList/PackedList.C b/src/OpenFOAM/containers/Bits/PackedList/PackedList.C index f1ecf2173886f8adf698dbb668ffd887d0982e3e..05d0e211b99b44ae66fb0b3c080f8681a4fdb9e2 100644 --- a/src/OpenFOAM/containers/Bits/PackedList/PackedList.C +++ b/src/OpenFOAM/containers/Bits/PackedList/PackedList.C @@ -145,6 +145,29 @@ bool Foam::PackedList<Width>::uniform() const } +template<unsigned Width> +bool Foam::PackedList<Width>::equal(const PackedList<Width>& other) const +{ + if (size() != other.size()) + { + return false; + } + + const label nblocks = num_blocks(size()); + const auto& rhs = other.blocks_; + + for (label blocki = 0; blocki < nblocks; ++blocki) + { + if (blocks_[blocki] != rhs[blocki]) + { + return false; + } + } + + return true; +} + + template<unsigned Width> Foam::labelList Foam::PackedList<Width>::values() const { diff --git a/src/OpenFOAM/containers/Bits/PackedList/PackedList.H b/src/OpenFOAM/containers/Bits/PackedList/PackedList.H index 6ebadbf1c71dda90d3216240e4b2daccfaf1f76a..278426c89c8eb7223d8e8128fce7a0be2492a321 100644 --- a/src/OpenFOAM/containers/Bits/PackedList/PackedList.H +++ b/src/OpenFOAM/containers/Bits/PackedList/PackedList.H @@ -286,6 +286,9 @@ public: //- True if all entries have identical values, and list is non-empty bool uniform() const; + //- Test for equality of sizes and the bits set + bool equal(const PackedList<Width>& other) const; + // Access @@ -495,7 +498,7 @@ public: }; -// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // //- Write List to Ostream, as per UList::writeList() with default length. // The default short-length is given by Detail::ListPolicy::short_length @@ -506,6 +509,15 @@ Ostream& operator<<(Ostream& os, const PackedList<Width>& list) } +//- Test for equality of sizes and the bits set +template<unsigned Width> +inline bool operator==(const PackedList<Width>& a, const PackedList<Width>& b); + +//- Test for inequality of sizes or the bits set +template<unsigned Width> +inline bool operator!=(const PackedList<Width>& a, const PackedList<Width>& b); + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/containers/Bits/PackedList/PackedListI.H b/src/OpenFOAM/containers/Bits/PackedList/PackedListI.H index 5470a2a7afae0b314ad14b335a59295765945355..56e481c3d4762f2ca4e1cb6bcbb69bdd9459f117 100644 --- a/src/OpenFOAM/containers/Bits/PackedList/PackedListI.H +++ b/src/OpenFOAM/containers/Bits/PackedList/PackedListI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -744,4 +744,28 @@ inline void Foam::PackedList<Width>::operator=(PackedList<Width>&& rhs) } +// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // + +template<unsigned Width> +inline bool Foam::operator== +( + const PackedList<Width>& a, + const PackedList<Width>& b +) +{ + return a.equal(b); +} + + +template<unsigned Width> +inline bool Foam::operator!= +( + const PackedList<Width>& a, + const PackedList<Width>& b +) +{ + return !a.equal(b); +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/containers/Bits/bitSet/bitSet.H b/src/OpenFOAM/containers/Bits/bitSet/bitSet.H index 00d943059686761e69f56e7efc65f14de9bbdea6..2bd37c0ba258423c97aa85c61e53e92ee4f091ea 100644 --- a/src/OpenFOAM/containers/Bits/bitSet/bitSet.H +++ b/src/OpenFOAM/containers/Bits/bitSet/bitSet.H @@ -120,6 +120,7 @@ protected: // A and B can have different sizes. Sizing behaviour as per orEq. bitSet& xorEq(const bitSet& other, const bool strict=true); + public: // Forward declaration of access classes @@ -554,7 +555,7 @@ public: }; -// Global Operators +// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // //- Write bitset to Ostream, as per bitSet::writeList() with default length //- of 40 items.