ENH: dedicated HashSetOps, HashTableOps namespaces

- relocated HashSetPlusEqOp and HashTablePlusEqOp to
  HashSetOps::plusEqOp and HashTableOps::plusEqOp, respectively

- additional functions for converting between a labelHashSet
  and a PackedBoolList or List<bool>:

  From lists selections to labelHashSet indices:

      HashSetOps::used(const PackedBoolList&);
      HashSetOps::used(const UList<bool>&);

  From labelHashSet to list forms:

      PackedBoolList bitset(const labelHashSet&);
      List<bool> bools(const labelHashSet&);
This commit is contained in:
Mark Olesen
2018-03-06 11:41:34 +01:00
parent 15f7260884
commit bcabe827f6
10 changed files with 340 additions and 112 deletions

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -27,13 +27,50 @@ Description
#include "hashedWordList.H"
#include "nil.H"
#include "HashOps.H"
#include "HashSet.H"
#include "Map.H"
#include "labelPairHashes.H"
#include "FlatOutput.H"
#include <algorithm>
using namespace Foam;
template<class Iter>
void printIf(const Iter& iter)
{
if (iter.found())
{
Info<< *iter;
}
else
{
Info<<"(null)";
}
}
template<class Key, class Hash>
void printMinMax(const HashSet<Key, Hash>& set)
{
const auto first = set.cbegin();
const auto last = set.cend();
const auto min = std::min_element(first, last);
const auto max = std::max_element(first, last);
Info<< "set: " << flatOutput(set) << nl;
Info<< " min=";
printIf(min);
Info<< nl;
Info<< " max=";
printIf(max);
Info<< nl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
@ -131,9 +168,14 @@ int main(int argc, char *argv[])
Info<< "create from Map<label>: ";
Info<< labelHashSet(mapA) << endl;
Info<<"combined toc: "
<< (wordHashSet(setA) | wordHashSet(tableA) | wordHashSet(tableB))
<< nl;
{
auto allToc =
(wordHashSet(setA) | wordHashSet(tableA) | wordHashSet(tableB));
Info<<"combined toc: " << flatOutput(allToc) << nl;
printMinMax(allToc);
}
labelHashSet setB
{
@ -226,6 +268,12 @@ int main(int argc, char *argv[])
Info << i << endl;
}
printMinMax(setD);
Info<< nl;
printMinMax(labelHashSet());
Info<< nl;
Info<< nl << "Test swapping, moving etc." << nl;
setA.insert({ "some", "more", "entries" });