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

- allows direct 'hashing' of fixed lists. Eg, triFace
This commit is contained in:
Mark Olesen
2018-08-01 13:01:43 +02:00
parent 35facb8208
commit 80f4ff87dd
3 changed files with 74 additions and 0 deletions

View File

@ -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

View File

@ -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());
}
// ************************************************************************* //