Commit b089e461 authored by Mark Olesen's avatar Mark Olesen

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

- also available as equal() member function
parent 5e46a129
......@@ -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});
......
......@@ -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
{
......
......@@ -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
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010, 2017-2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2010, 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);
}
// ************************************************************************* //
......@@ -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.
......
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