ENH: add HashTableOps::values() service function

- extract a list of the HashTable values, optionally sorted.
This commit is contained in:
Mark Olesen
2018-08-07 20:17:38 +02:00
parent 9160dad6ba
commit 32a332f5f1

View File

@ -140,6 +140,29 @@ struct plusEqOp
} }
}; };
//- List of values from HashTable, optionally sorted.
template<class T, class Key, class Hash>
List<T> values(const HashTable<T, Key, Hash>& tbl, const bool doSort=false)
{
List<T> output(tbl.size());
label i=0;
forAllConstIters(tbl, iter)
{
output[i] = iter.object();
++i;
}
if (doSort)
{
Foam::sort(output);
}
return output;
}
} // End namespace HashTableOps } // End namespace HashTableOps