Skip to content
Snippets Groups Projects
Commit 180a2848 authored by Mark OLESEN's avatar Mark OLESEN Committed by Andrew Heather
Browse files

ENH: add '==' and '!=' operators for PackedList/bitSet

- also available as equal() member function
parent e1609d16
Branches
Tags
No related merge requests found
...@@ -76,6 +76,9 @@ int main(int argc, char *argv[]) ...@@ -76,6 +76,9 @@ int main(int argc, char *argv[])
bitSet set2b(set2, labelRange(15, 30)); bitSet set2b(set2, labelRange(15, 30));
Info<<"bitSet slice(15,30) :"; report(set2b, true); 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}); FixedList<label, 4> locs({ -1, 3, 4, 12});
......
...@@ -145,6 +145,29 @@ bool Foam::PackedList<Width>::uniform() const ...@@ -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> template<unsigned Width>
Foam::labelList Foam::PackedList<Width>::values() const Foam::labelList Foam::PackedList<Width>::values() const
{ {
......
...@@ -286,6 +286,9 @@ public: ...@@ -286,6 +286,9 @@ public:
//- True if all entries have identical values, and list is non-empty //- True if all entries have identical values, and list is non-empty
bool uniform() const; bool uniform() const;
//- Test for equality of sizes and the bits set
bool equal(const PackedList<Width>& other) const;
// Access // Access
...@@ -495,7 +498,7 @@ public: ...@@ -495,7 +498,7 @@ public:
}; };
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
//- Write List to Ostream, as per UList::writeList() with default length. //- Write List to Ostream, as per UList::writeList() with default length.
// The default short-length is given by Detail::ListPolicy::short_length // The default short-length is given by Detail::ListPolicy::short_length
...@@ -506,6 +509,15 @@ Ostream& operator<<(Ostream& os, const PackedList<Width>& list) ...@@ -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 } // End namespace Foam
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation | Copyright (C) 2011-2016 OpenFOAM Foundation
...@@ -744,4 +744,28 @@ inline void Foam::PackedList<Width>::operator=(PackedList<Width>&& rhs) ...@@ -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);
}
// ************************************************************************* // // ************************************************************************* //
...@@ -120,6 +120,7 @@ protected: ...@@ -120,6 +120,7 @@ protected:
// A and B can have different sizes. Sizing behaviour as per orEq. // A and B can have different sizes. Sizing behaviour as per orEq.
bitSet& xorEq(const bitSet& other, const bool strict=true); bitSet& xorEq(const bitSet& other, const bool strict=true);
public: public:
// Forward declaration of access classes // Forward declaration of access classes
...@@ -554,7 +555,7 @@ public: ...@@ -554,7 +555,7 @@ public:
}; };
// Global Operators // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
//- Write bitset to Ostream, as per bitSet::writeList() with default length //- Write bitset to Ostream, as per bitSet::writeList() with default length
//- of 40 items. //- of 40 items.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment