ENH: additional IndirectList static methods

- uniq() : creates an IndirectList with duplicated entries
  filtered out

- subset() : creates an IndirectList with positions that satisfy
  a condition predicate.

- subset_if() : creates an IndirectList with values that satisfy a
  given predicate.

  An indirect subset will be cheaper than creating a subset copy
  of the original data, and also allows modification.

STYLE: combine UIndirectList.H into UIndirectList.H (reduce file clutter)
This commit is contained in:
Mark Olesen
2022-05-04 00:33:53 +02:00
parent 7afebef509
commit a34357b1a6
27 changed files with 292 additions and 150 deletions

View File

@ -151,6 +151,10 @@ int main(int argc, char *argv[])
<< subsetList(test6, evenNonZero) << nl
<< endl;
Info<< "Subset of non-zero, even values: "
<< IndirectList<label>::subset_if(test6, evenNonZero) << nl
<< endl;
test6.append(identity(13, 12));
Info<< "Randomized: " << flatOutput(test6) << endl;

View File

@ -27,7 +27,7 @@ Description
\*---------------------------------------------------------------------------*/
#include "UIndirectList.H"
#include "IndirectList.H"
#include "DynamicList.H"
#include "IOstreams.H"
#include "ListOps.H"

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -190,6 +190,8 @@ int main(int argc, char *argv[])
<< nl;
Info<< "Subset = " << subsetList(values1, limiter) << nl;
Info<< "Subset = "
<< IndirectList<scalar>::subset_if(values1, limiter) << nl;
Info<< nl << "test clip() with limiter: " << limiter << nl;
for (const scalar& val : values1)

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2017-2019 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -28,7 +28,9 @@ Description
\*---------------------------------------------------------------------------*/
#include "SortList.H"
#include "SortableList.H"
#include "IndirectList.H"
#include "ListOps.H"
#include "HashSet.H"
#include "stringOps.H"
@ -49,6 +51,18 @@ void printInfo(const SortableList<T>& list)
int main(int argc, char *argv[])
{
{
const labelList orig({7, 9, 7, 12, 9, 1, 12, 2, 4, 7, 4, 0});
Info<< "original list: " << flatOutput(orig) << endl;
auto unique = IndirectList<label>::uniq(orig);
Info<< "unique list: " << flatOutput(unique) << endl;
Info<< "unique idx : " << flatOutput(unique.addressing()) << endl;
}
const labelList orig({7, 9, 1, 2, 4, 7, 4, 0});
labelList order;