wordRes.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2016-2019 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "wordRes.H"
29 
30 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
31 
33 {
34  wordRes output(input.size());
35 
36  // Use linear List search instead of HashSet, since the lists are
37  // normally fairly small and mostly just have unique entries
38  // anyhow. This reduces the overall overhead.
39 
40  List<bool> duplicate(input.size(), false); // Track duplicates
41 
42  label count = 0;
43 
44  forAll(input, i)
45  {
46  const wordRe& val = input[i];
47 
48  const label next = input.find(val, i+1);
49 
50  if (next > i)
51  {
52  duplicate[next] = true; // Duplicate
53  }
54 
55  if (!duplicate[i])
56  {
57  output[count] = val;
58  ++count;
59  }
60  }
61 
62  output.resize(count);
63 
64  return output;
65 }
66 
67 
68 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
69 
71 {
72  List<wordRe> input = *this;
73 
74  wordRes& output = *this;
75 
76  // Use linear List search instead of HashSet, since the lists are
77  // normally fairly small and mostly just have unique entries
78  // anyhow. This reduces the overall overhead.
79 
80  List<bool> duplicate(input.size(), false); // Track duplicates
81 
82  label count = 0;
83 
84  forAll(input, i)
85  {
86  wordRe& val = input[i];
87 
88  const label next = input.find(val, i+1);
89 
90  if (next > i)
91  {
92  duplicate[next] = true; // Duplicate
93  }
94 
95  if (!duplicate[i])
96  {
97  output[count] = std::move(val);
98  ++count;
99  }
100  }
101 
102  output.resize(count);
103 }
104 
105 
106 // ************************************************************************* //
wordRes.H
Foam::output
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:66
Foam::wordRe
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition: wordRe.H:80
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::wordRes::uniq
void uniq()
Filter out duplicate entries (inplace).
Definition: wordRes.C:70
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::List< bool >
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::input
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:55