diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedBoolList.C b/src/OpenFOAM/containers/Lists/PackedList/PackedBoolList.C index ce9efbfeb6..79a383a685 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedBoolList.C +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedBoolList.C @@ -89,42 +89,6 @@ bool Foam::PackedBoolList::bitorPrepare } - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -Foam::PackedBoolList::PackedBoolList(Istream& is) -: - PackedList<1>() -{ - is >> *this; -} - - -// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // - -Foam::Xfer Foam::PackedBoolList::used() const -{ - labelList lst(this->count()); - - if (lst.size()) - { - label nElem = 0; - - forAll(*this, elemI) - { - if (get(elemI)) - { - lst[nElem++] = elemI; - } - } - - lst.setSize(nElem); - } - - return lst.xfer(); -} - - template Foam::label Foam::PackedBoolList::setIndices(const LabelListType& indices) { @@ -160,6 +124,70 @@ Foam::label Foam::PackedBoolList::unsetIndices(const LabelListType& indices) } +template +Foam::label Foam::PackedBoolList::subsetIndices(const LabelListType& indices) +{ + // handle trivial case + if (empty() || indices.empty()) + { + clear(); + return 0; + } + + // normal case + PackedBoolList anded; + anded.reserve(size()); + + label cnt = 0; + forAll(indices, elemI) + { + const label& index = indices[elemI]; + if (operator[](index)) + { + anded.set(index); + ++cnt; + } + } + + transfer(anded); + return cnt; +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::PackedBoolList::PackedBoolList(Istream& is) +: + PackedList<1>() +{ + is >> *this; +} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +void Foam::PackedBoolList::set(const PackedList<1>& lst) +{ + // extend addressable area if needed, return maximum size possible + label len = 0; + const bool needTrim = bitorPrepare(lst, len); + + // operate directly with the underlying storage + StorageList& lhs = this->storage(); + const StorageList& rhs = lst.storage(); + + for (label i=0; i < len; ++i) + { + lhs[i] |= rhs[i]; + } + + if (needTrim) + { + trim(); + } +} + + Foam::label Foam::PackedBoolList::set(const UList