From 80f4ff87dd8de93466120ea5f2f3dc23e5666b84 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Wed, 1 Aug 2018 13:01:43 +0200 Subject: [PATCH] ENH: allow use of FixedList<label,N> for bitSet construct/set/unset - allows direct 'hashing' of fixed lists. Eg, triFace --- applications/test/bitSet1/Test-bitSet1.C | 14 +++++++ src/OpenFOAM/containers/Bits/bitSet/bitSet.H | 23 ++++++++++++ .../containers/Bits/bitSet/bitSetTemplates.C | 37 +++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/applications/test/bitSet1/Test-bitSet1.C b/applications/test/bitSet1/Test-bitSet1.C index e838f2b0a96..9104b34dc5c 100644 --- a/applications/test/bitSet1/Test-bitSet1.C +++ b/applications/test/bitSet1/Test-bitSet1.C @@ -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; diff --git a/src/OpenFOAM/containers/Bits/bitSet/bitSet.H b/src/OpenFOAM/containers/Bits/bitSet/bitSet.H index 2acade14166..7be1c35480c 100644 --- a/src/OpenFOAM/containers/Bits/bitSet/bitSet.H +++ b/src/OpenFOAM/containers/Bits/bitSet/bitSet.H @@ -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 diff --git a/src/OpenFOAM/containers/Bits/bitSet/bitSetTemplates.C b/src/OpenFOAM/containers/Bits/bitSet/bitSetTemplates.C index e55cc6c77da..a41ad03c37f 100644 --- a/src/OpenFOAM/containers/Bits/bitSet/bitSetTemplates.C +++ b/src/OpenFOAM/containers/Bits/bitSet/bitSetTemplates.C @@ -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()); +} + + // ************************************************************************* // -- GitLab