HashOps.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) 2018-2023 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 "HashOps.H"
29 #include "bitSet.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
34 {
36 
37  if (select.any())
38  {
39  output.reserve(select.count());
40 
41  for (label i = select.find_first(); i >= 0; i = select.find_next(i))
42  {
43  output.insert(i);
44  }
45  }
46 
47  return output;
48 }
49 
50 
52 {
53  const label len = select.size();
54 
55  // No idea of the sparseness, just assume 1/8
56  labelHashSet output(len/4);
57 
58  for (label i = 0; i < len; ++i)
59  {
60  if (select[i])
61  {
62  output.insert(i);
63  }
64  }
65 
66  return output;
67 }
68 
69 
71 {
73  output.setMany(locations.begin(), locations.end());
74 
75  return output;
76 }
77 
78 
80 {
81  auto const max = std::max_element(locations.begin(), locations.end());
82  const label len = (max != locations.end() ? (1 + *max) : 0);
83 
84  if (len <= 0)
85  {
86  return List<bool>();
87  }
88 
89  List<bool> output(len, false);
90 
91  for (const label i : locations)
92  {
93  if (i >= 0)
94  {
95  output[i] = true;
96  }
97  }
98 
99  return output;
100 }
101 
102 
103 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
labelHashSet used(const bitSet &select)
Convert a bitset to a labelHashSet of the indices used.
Definition: HashOps.C:26
iterator begin()
Definition: HashSet.C:453
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
List< bool > select(const label n, const labelUList &locations)
Construct a selection list of bools (all false) with the given pre-size, subsequently add specified l...
Definition: BitOps.C:134
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
List< bool > bools(const labelHashSet &locations)
Transform the on locations to a boolList, with true for each non-negative location and false for all ...
Definition: HashOps.C:72
iterator end() noexcept
Definition: HashSet.C:486
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:59
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:44
bitSet bitset(const labelHashSet &locations)
Transform the on locations to a bitSet.
Definition: HashOps.C:63