Commit 80f4ff87 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: allow use of FixedList<label,N> for bitSet construct/set/unset

- allows direct 'hashing' of fixed lists. Eg, triFace
parent 35facb82
......@@ -73,6 +73,20 @@ int main(int argc, char *argv[])
bitSet set2(100, { -1, 10, 25, 45});
Info<<"bitSet(label, labels): "; report(set2, true);
{
FixedList<label, 4> locs({ -1, 3, 4, 12});
bitSet set3a(20, locs);
Info<<"bitSet(FixedList<label>): "; report(set3a, true);
bitSet set3b(locs);
Info<<"bitSet(FixedList<label>): "; report(set3b, true);
set3b.unset(FixedList<label, 3>({ 1, 2, 3}));
Info<<"bitSet unset(FixedList<label>): "; report(set3b, true);
}
Info<< "End\n" << endl;
return 0;
......
......@@ -164,6 +164,11 @@ public:
//- subsequently add specified locations as 1.
inline bitSet(const label n, const labelUIndList& locations);
//- Construct with given size with all bits set to 0,
//- subsequently add specified locations as 1.
template<unsigned N>
bitSet(const label n, const FixedList<label, N>& locations);
//- Construct with given size with all bits set to 0,
//- subsequently add specified locations as 1.
inline bitSet(const label n, std::initializer_list<label> locations);
......@@ -176,6 +181,11 @@ public:
//- and populate with specified locations as 1.
inline explicit bitSet(const labelUIndList& locations);
//- Construct with automatic sizing (filled with 0),
//- and populate with specified locations as 1.
template<unsigned N>
explicit bitSet(const FixedList<label, N>& locations);
//- Clone
inline autoPtr<bitSet> clone() const;
......@@ -366,6 +376,13 @@ public:
// \return number of locations changed
inline label set(const labelUIndList& locations);
//- Set the listed locations to true.
// Does auto-vivify for non-existent entries.
//
// \return number of locations changed
template<unsigned N>
label set(const FixedList<label, N>& locations);
//- Unset the locations listed by the iterator range,
//- never auto-vivify entries.
//
......@@ -383,6 +400,12 @@ public:
// \return number of locations changed
inline label unset(const labelUIndList& locations);
//- Unset the listed locations, never auto-vivifies.
//
// \return number of locations changed
template<unsigned N>
label unset(const FixedList<label, N>& locations);
// Access helpers
......
......@@ -24,6 +24,29 @@ License
\*---------------------------------------------------------------------------*/
#include <algorithm>
#include "FixedList.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<unsigned N>
Foam::bitSet::bitSet(const label n, const FixedList<label, N>& locations)
:
bitSet(n)
{
setMany(locations.begin(), locations.end());
}
template<unsigned N>
Foam::bitSet::bitSet(const FixedList<label, N>& locations)
:
bitSet()
{
setMany(locations.begin(), locations.end());
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
......@@ -70,4 +93,18 @@ Foam::label Foam::bitSet::unset(InputIter first, InputIter last)
}
template<unsigned N>
Foam::label Foam::bitSet::set(const FixedList<label, N>& locations)
{
return setMany(locations.begin(), locations.end());
}
template<unsigned N>
Foam::label Foam::bitSet::unset(const FixedList<label, N>& locations)
{
return unset(locations.begin(), locations.end());
}
// ************************************************************************* //
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