Commit 9be9f02a authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: bitSet, PackedList copy construct a subset

Eg,
    processorPolyPatch pp = ...;

    UOPstream toNbr(pp.neighbProcNo(), pBufs);
    toNbr << PackedList<Width>(faceValues, pp.range());
parent 51c32360
......@@ -73,6 +73,9 @@ int main(int argc, char *argv[])
bitSet set2(100, { -1, 10, 25, 45});
Info<<"bitSet(label, labels): "; report(set2, true);
bitSet set2b(set2, labelRange(15, 30));
Info<<"bitSet slice(15,30) :"; report(set2b, true);
{
FixedList<label, 4> locs({ -1, 3, 4, 12});
......
......@@ -24,6 +24,65 @@ License
\*---------------------------------------------------------------------------*/
#include "PackedList.H"
#include "labelRange.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<unsigned Width>
Foam::PackedList<Width>::PackedList
(
const PackedList<Width>& list,
const labelUList& addr
)
:
PackedList<Width>(addr.size())
{
const label len = addr.size();
for (label i = 0; i < len; ++i)
{
set(i, list.get(addr[i]));
}
}
template<unsigned Width>
Foam::PackedList<Width>::PackedList
(
const PackedList<Width>& list,
const labelUIndList& addr
)
:
PackedList<Width>(addr.size())
{
const label len = addr.size();
for (label i = 0; i < len; ++i)
{
set(i, list.get(addr[i]));
}
}
template<unsigned Width>
Foam::PackedList<Width>::PackedList
(
const PackedList<Width>& list,
const labelRange& range
)
:
PackedList<Width>(range.size())
{
label pos = range.start();
const label len = range.size();
for (label i = 0; i < len; ++i)
{
set(i, list.get(pos));
++pos;
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
......
......@@ -104,6 +104,8 @@ namespace Foam
// Forward declarations
template<unsigned Width> class PackedList;
class labelRange;
class Istream;
class Ostream;
......@@ -239,10 +241,19 @@ public:
inline PackedList(Istream& is);
//- Copy construct
inline PackedList(const PackedList<Width>& rhs);
inline PackedList(const PackedList<Width>& list);
//- Move construct
inline PackedList(PackedList<Width>&& rhs);
inline PackedList(PackedList<Width>&& list);
//- Copy construct a subset
PackedList(const PackedList<Width>& list, const labelUList& addr);
//- Copy construct a subset
PackedList(const PackedList<Width>& list, const labelUIndList& addr);
//- Copy construct a subset range
PackedList(const PackedList<Width>& list, const labelRange& range);
//- Construct from a list of values
inline explicit PackedList(const labelUList& values);
......
......@@ -203,20 +203,20 @@ inline Foam::PackedList<Width>::PackedList(Istream& is)
template<unsigned Width>
inline Foam::PackedList<Width>::PackedList(const PackedList<Width>& rhs)
inline Foam::PackedList<Width>::PackedList(const PackedList<Width>& list)
:
blocks_(rhs.blocks_),
size_(rhs.size_)
blocks_(list.blocks_),
size_(list.size_)
{}
template<unsigned Width>
inline Foam::PackedList<Width>::PackedList(PackedList<Width>&& rhs)
inline Foam::PackedList<Width>::PackedList(PackedList<Width>&& list)
:
blocks_(std::move(rhs.blocks_)),
size_(rhs.size_)
blocks_(std::move(list.blocks_)),
size_(list.size_)
{
rhs.size_ = 0;
list.size_ = 0;
}
......@@ -228,8 +228,8 @@ inline Foam::PackedList<Width>::PackedList(const labelUList& values)
{
const label len = values.size();
// Could add more intelligent filling (blockwise), but likely done
// fairly infrequently
// Could add more intelligent filling (blockwise),
// but likely done fairly infrequently
for (label i = 0; i < len; ++i)
{
......@@ -247,8 +247,8 @@ inline Foam::PackedList<Width>::PackedList(const labelUIndList& values)
{
const label len = values.size();
// Could add more intelligent filling (blockwise), but likely done
// fairly infrequently
// Could add more intelligent filling (blockwise),
// but likely done fairly infrequently
for (label i = 0; i < len; ++i)
{
......
......@@ -296,6 +296,47 @@ Foam::bitSet::bitSet(Istream& is)
}
Foam::bitSet::bitSet(const bitSet& bitset, const labelUList& addr)
:
bitSet(addr.size())
{
const label len = addr.size();
for (label i = 0; i < len; ++i)
{
set(i, bitset.get(addr[i]));
}
}
Foam::bitSet::bitSet(const bitSet& bitset, const labelUIndList& addr)
:
bitSet(addr.size())
{
const label len = addr.size();
for (label i = 0; i < len; ++i)
{
set(i, bitset.get(addr[i]));
}
}
Foam::bitSet::bitSet(const bitSet& bitset, const labelRange& range)
:
bitSet(range.size())
{
label pos = range.start();
const label len = range.size();
for (label i = 0; i < len; ++i)
{
set(i, bitset.get(pos));
++pos;
}
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
void Foam::bitSet::assign(const UList<bool>& bools)
......
......@@ -46,7 +46,6 @@ See also
#include "className.H"
#include "PackedList.H"
#include "UIndirectList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -153,6 +152,15 @@ public:
//- Move construct
inline bitSet(bitSet&& bitset);
//- Copy construct a subset
bitSet(const bitSet& bitset, const labelUList& addr);
//- Copy construct a subset
bitSet(const bitSet& bitset, const labelUIndList& addr);
//- Copy construct a subset range
bitSet(const bitSet& bitset, const labelRange& range);
//- Construct from a list of bools
inline explicit bitSet(const UList<bool>& bools);
......
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