mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: allow early completion in PackedBoolList::used()
- can stop producing content when the target number of entries has been reached. - change return type to labelList instead an Xfer container. This allows return-value-optimization and avoids a surrounding allocation. This potentially breaks existing code. - make PackedList and PackedBoolList moveable. Drop xfer wrappers.
This commit is contained in:
@ -144,18 +144,18 @@ int main(int argc, char *argv[])
|
||||
Info<< "\ntest Istream constructor\n";
|
||||
|
||||
list4.printInfo(Info, true);
|
||||
Info<< list4 << " indices: " << list4.used()() << nl;
|
||||
Info<< list4 << " indices: " << list4.used() << nl;
|
||||
|
||||
Info<< "\nassign from labelList\n";
|
||||
list4 = labelList{0, 1, 2, 3, 12, 13, 14, 19, 20, 21};
|
||||
|
||||
list4.printInfo(Info, true);
|
||||
Info<< list4 << " indices: " << list4.used()() << nl;
|
||||
Info<< list4 << " indices: " << list4.used() << nl;
|
||||
|
||||
// Not yet:
|
||||
// PackedBoolList list5{0, 1, 2, 3, 12, 13, 14, 19, 20, 21};
|
||||
// list5.printInfo(Info, true);
|
||||
// Info<< list5 << " indices: " << list5.used()() << nl;
|
||||
// Info<< list5 << " indices: " << list5.used() << nl;
|
||||
|
||||
Info<< "\nassign from indices\n";
|
||||
list4.read
|
||||
@ -168,7 +168,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
|
||||
list4.printInfo(Info, true);
|
||||
Info<< list4 << " indices: " << list4.used()() << nl;
|
||||
Info<< list4 << " indices: " << list4.used() << nl;
|
||||
|
||||
boolList bools(list4.size());
|
||||
forAll(list4, i)
|
||||
|
||||
@ -265,26 +265,28 @@ Foam::label Foam::PackedBoolList::subset(const labelUIndList& indices)
|
||||
}
|
||||
|
||||
|
||||
Foam::Xfer<Foam::labelList> Foam::PackedBoolList::used() const
|
||||
Foam::labelList Foam::PackedBoolList::used() const
|
||||
{
|
||||
labelList lst(this->count());
|
||||
// Number of used (set) entries
|
||||
const label cnt = this->count();
|
||||
|
||||
if (lst.size())
|
||||
labelList lst(cnt);
|
||||
|
||||
if (cnt)
|
||||
{
|
||||
label nElem = 0;
|
||||
// The length of the input list
|
||||
const label len = this->size();
|
||||
|
||||
forAll(*this, elemI)
|
||||
for (label i=0, usedi=0; (i < len && usedi < cnt); ++i)
|
||||
{
|
||||
if (get(elemI))
|
||||
if (get(i))
|
||||
{
|
||||
lst[nElem++] = elemI;
|
||||
lst[usedi++] = i;
|
||||
}
|
||||
}
|
||||
|
||||
lst.setSize(nElem);
|
||||
}
|
||||
|
||||
return lst.xfer();
|
||||
return lst;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -91,7 +91,7 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
inline PackedBoolList();
|
||||
PackedBoolList() = default;
|
||||
|
||||
//- Construct from Istream
|
||||
PackedBoolList(Istream& is);
|
||||
@ -102,17 +102,17 @@ public:
|
||||
//- Construct with given size and value for all elements
|
||||
inline PackedBoolList(const label size, const bool val);
|
||||
|
||||
//- Copy constructor
|
||||
//- Copy construct
|
||||
inline PackedBoolList(const PackedBoolList& lst);
|
||||
|
||||
//- Copy constructor
|
||||
//- Copy construct
|
||||
explicit inline PackedBoolList(const PackedList<1>& lst);
|
||||
|
||||
//- Construct by transferring the parameter contents
|
||||
inline PackedBoolList(const Xfer<PackedBoolList>& lst);
|
||||
//- Move construct
|
||||
inline PackedBoolList(PackedBoolList&& lst);
|
||||
|
||||
//- Construct by transferring the parameter contents
|
||||
inline PackedBoolList(const Xfer<PackedList<1>>& lst);
|
||||
//- Move construct
|
||||
inline PackedBoolList(PackedList<1>&& lst);
|
||||
|
||||
//- Construct with given size and list of labels to set as true.
|
||||
inline PackedBoolList(const label size, const labelUList& indices);
|
||||
@ -137,7 +137,7 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
// Access
|
||||
|
||||
using PackedList<1>::set;
|
||||
using PackedList<1>::unset;
|
||||
@ -175,12 +175,11 @@ public:
|
||||
// Return number of elements subsetted.
|
||||
label subset(const labelUIndList& indices);
|
||||
|
||||
|
||||
//- Return indices of the used (true) elements as a list of labels
|
||||
Xfer<labelList> used() const;
|
||||
labelList used() const;
|
||||
|
||||
|
||||
// Edit
|
||||
// Edit
|
||||
|
||||
//- Transfer the contents of the argument list into this list
|
||||
//- and annul the argument list.
|
||||
@ -190,21 +189,24 @@ public:
|
||||
//- and annul the argument list.
|
||||
inline void transfer(PackedList<1>& lst);
|
||||
|
||||
//- 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 operator.
|
||||
//- Copy assignment
|
||||
inline void operator=(const PackedBoolList& lst);
|
||||
|
||||
//- Assignment operator.
|
||||
//- Copy assignment
|
||||
inline void operator=(const PackedList<1>& lst);
|
||||
|
||||
//- Move assignment
|
||||
inline void operator=(PackedBoolList&& lst);
|
||||
|
||||
//- Move assignment
|
||||
inline void operator=(PackedList<1>&& lst);
|
||||
|
||||
//- Assignment operator.
|
||||
void operator=(const UList<bool>& lst);
|
||||
|
||||
|
||||
@ -25,12 +25,6 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::PackedBoolList::PackedBoolList()
|
||||
:
|
||||
PackedList<1>()
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::PackedBoolList::PackedBoolList(const label size)
|
||||
:
|
||||
PackedList<1>(size)
|
||||
@ -59,18 +53,20 @@ inline Foam::PackedBoolList::PackedBoolList(const PackedList<1>& lst)
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::PackedBoolList::PackedBoolList(const Xfer<PackedBoolList>& lst)
|
||||
inline Foam::PackedBoolList::PackedBoolList(PackedBoolList&& lst)
|
||||
:
|
||||
PackedList<1>()
|
||||
{
|
||||
transfer(lst());
|
||||
transfer(lst);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::PackedBoolList::PackedBoolList(const Xfer<PackedList<1>>& lst)
|
||||
inline Foam::PackedBoolList::PackedBoolList(PackedList<1>&& lst)
|
||||
:
|
||||
PackedList<1>(lst)
|
||||
{}
|
||||
PackedList<1>()
|
||||
{
|
||||
transfer(lst);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::PackedBoolList::PackedBoolList(const UList<bool>& lst)
|
||||
@ -147,12 +143,6 @@ inline void Foam::PackedBoolList::transfer(PackedList<1>& lst)
|
||||
}
|
||||
|
||||
|
||||
inline Foam::Xfer<Foam::PackedBoolList> Foam::PackedBoolList::xfer()
|
||||
{
|
||||
return xferMove(*this);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
inline void Foam::PackedBoolList::operator=(const bool val)
|
||||
@ -173,6 +163,18 @@ inline void Foam::PackedBoolList::operator=(const PackedList<1>& lst)
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::PackedBoolList::operator=(PackedBoolList&& lst)
|
||||
{
|
||||
transfer(lst);
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::PackedBoolList::operator=(PackedList<1>&& lst)
|
||||
{
|
||||
transfer(lst);
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::PackedBoolList::operator=(const labelUList& indices)
|
||||
{
|
||||
clear();
|
||||
|
||||
@ -141,16 +141,16 @@ void Foam::PackedList<nBits>::flip()
|
||||
|
||||
|
||||
template<unsigned nBits>
|
||||
Foam::Xfer<Foam::labelList> Foam::PackedList<nBits>::values() const
|
||||
Foam::labelList Foam::PackedList<nBits>::values() const
|
||||
{
|
||||
labelList elems(size_);
|
||||
|
||||
forAll(*this, i)
|
||||
for (label i=0; i < size_; ++i)
|
||||
{
|
||||
elems[i] = get(i);
|
||||
}
|
||||
|
||||
return elems.xfer();
|
||||
return elems;
|
||||
}
|
||||
|
||||
|
||||
@ -522,6 +522,13 @@ void Foam::PackedList<nBits>::operator=(const PackedList<nBits>& lst)
|
||||
}
|
||||
|
||||
|
||||
template<unsigned nBits>
|
||||
void Foam::PackedList<nBits>::operator=(PackedList<nBits>&& lst)
|
||||
{
|
||||
transfer(lst);
|
||||
}
|
||||
|
||||
|
||||
template<unsigned nBits>
|
||||
void Foam::PackedList<nBits>::operator=(const labelUList& lst)
|
||||
{
|
||||
|
||||
@ -235,11 +235,11 @@ public:
|
||||
//- Construct from Istream
|
||||
inline PackedList(Istream& is);
|
||||
|
||||
//- Copy constructor
|
||||
//- Copy construct
|
||||
inline PackedList(const PackedList<nBits>& lst);
|
||||
|
||||
//- Construct by transferring the parameter contents
|
||||
inline PackedList(const Xfer<PackedList<nBits>>& lst);
|
||||
//- Move construct
|
||||
inline PackedList(PackedList<nBits>&& lst);
|
||||
|
||||
//- Construct from a list of labels
|
||||
explicit inline PackedList(const labelUList& lst);
|
||||
@ -297,7 +297,7 @@ public:
|
||||
unsigned int count() const;
|
||||
|
||||
//- Return the values as a list of labels
|
||||
Xfer<labelList> values() const;
|
||||
labelList values() const;
|
||||
|
||||
//- Print bit patterns, optionally output unused elements
|
||||
//
|
||||
@ -356,9 +356,6 @@ public:
|
||||
// and annul the argument list.
|
||||
inline void transfer(PackedList<nBits>& lst);
|
||||
|
||||
//- Transfer contents to the Xfer container
|
||||
inline Xfer<PackedList<nBits>> xfer();
|
||||
|
||||
|
||||
// IO
|
||||
|
||||
@ -407,9 +404,12 @@ public:
|
||||
//- Assignment of all entries to the given value. Takes linear time.
|
||||
inline void operator=(const unsigned int val);
|
||||
|
||||
//- Assignment operator.
|
||||
//- Copy assignment.
|
||||
void operator=(const PackedList<nBits>& lst);
|
||||
|
||||
//- Move assignment.
|
||||
void operator=(PackedList<nBits>&& lst);
|
||||
|
||||
//- Assignment operator.
|
||||
void operator=(const labelUList& lst);
|
||||
|
||||
|
||||
@ -223,9 +223,13 @@ inline Foam::PackedList<nBits>::PackedList(const PackedList<nBits>& lst)
|
||||
|
||||
|
||||
template<unsigned nBits>
|
||||
inline Foam::PackedList<nBits>::PackedList(const Xfer<PackedList<nBits>>& lst)
|
||||
inline Foam::PackedList<nBits>::PackedList(PackedList<nBits>&& lst)
|
||||
:
|
||||
PackedListCore(),
|
||||
StorageList(),
|
||||
size_(0)
|
||||
{
|
||||
transfer(lst());
|
||||
transfer(lst);
|
||||
}
|
||||
|
||||
|
||||
@ -956,13 +960,6 @@ inline void Foam::PackedList<nBits>::transfer(PackedList<nBits>& lst)
|
||||
}
|
||||
|
||||
|
||||
template<unsigned nBits>
|
||||
inline Foam::Xfer<Foam::PackedList<nBits>> Foam::PackedList<nBits>::xfer()
|
||||
{
|
||||
return xferMove(*this);
|
||||
}
|
||||
|
||||
|
||||
template<unsigned nBits>
|
||||
inline unsigned int Foam::PackedList<nBits>::get(const label i) const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user