From 32a332f5f1d9b3d55d69e2c0d6dca3f66cfedd4b Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 7 Aug 2018 20:17:38 +0200 Subject: [PATCH] ENH: add HashTableOps::values() service function - extract a list of the HashTable values, optionally sorted. --- .../containers/HashTables/HashOps/HashOps.H | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/OpenFOAM/containers/HashTables/HashOps/HashOps.H b/src/OpenFOAM/containers/HashTables/HashOps/HashOps.H index 97f308f7ce..8782df0810 100644 --- a/src/OpenFOAM/containers/HashTables/HashOps/HashOps.H +++ b/src/OpenFOAM/containers/HashTables/HashOps/HashOps.H @@ -140,6 +140,29 @@ struct plusEqOp } }; + +//- List of values from HashTable, optionally sorted. +template +List values(const HashTable& tbl, const bool doSort=false) +{ + List output(tbl.size()); + + label i=0; + + forAllConstIters(tbl, iter) + { + output[i] = iter.object(); + ++i; + } + + if (doSort) + { + Foam::sort(output); + } + + return output; +} + } // End namespace HashTableOps