From 95a33c2f68f3a7bcc723c0d349bf44dbf318223b Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 14 Feb 2019 11:03:04 +0100 Subject: [PATCH] ENH: wordRes::uniq() removes all duplicates - previously just removed duplicate literals, but now remove any duplicates. - Replace previous wordHashSet implementation with a linear search instead. The lists are normally fairly small and mostly just have unique entries anyhow. This reduces the overall overhead. --- applications/test/wordRe/Test-wordRe.C | 31 +++++++++- .../primitives/strings/wordRes/wordRes.C | 61 ++++++++++++++----- .../primitives/strings/wordRes/wordRes.H | 10 +-- 3 files changed, 80 insertions(+), 22 deletions(-) diff --git a/applications/test/wordRe/Test-wordRe.C b/applications/test/wordRe/Test-wordRe.C index ca05244c5e..8917e84764 100644 --- a/applications/test/wordRe/Test-wordRe.C +++ b/applications/test/wordRe/Test-wordRe.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -36,6 +36,7 @@ Description #include "keyType.H" #include "wordRes.H" #include "predicates.H" +#include "Random.H" using namespace Foam; @@ -139,6 +140,34 @@ int main(int argc, char *argv[]) Info<< "string match: " << string("x.*")("xyz") << nl; Info<< "string match: " << string("x.*")(keyre) << nl; + + // Test uniq + { + Random rnd; + const label last = wres1.size()-1; + + for (label i = 0; i < 8; ++i) + { + // Make a copy + wordRe wre(wres1[rnd.position