The open source CFD toolbox
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 OpenCFD Ltd.
9-------------------------------------------------------------------------------
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
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#include <algorithm>
32
33// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34
36{
37 labelHashSet output(0);
38
39 if (select.any())
40 {
41 output.resize(2*select.count());
42
43 for (label i = select.find_first(); i >= 0; i = select.find_next(i))
44 {
45 output.insert(i);
46 }
47 }
48
49 return output;
50}
51
52
54{
55 const label len = select.size();
56
57 // No idea of the sparseness, just assume 1/8
58 labelHashSet output(len/4);
59
60 for (label i = 0; i < len; ++i)
61 {
62 if (select[i])
63 {
64 output.insert(i);
65 }
66 }
67
68 return output;
69}
70
71
73{
74 bitSet output;
75 output.setMany(locations.begin(), locations.end());
76
77 return output;
78}
79
80
82{
83 auto const max = std::max_element(locations.begin(), locations.end());
84 const label len = (max != locations.end() ? (1 + *max) : 0);
85
86 if (len <= 0)
87 {
88 return List<bool>();
89 }
90
91 List<bool> output(len, false);
92
93 for (const label i : locations)
94 {
95 if (i >= 0)
96 {
97 output[i] = true;
98 }
99 }
100
101 return output;
102}
103
104
105// ************************************************************************* //
Y[inertIndex] max(0.0)
iterator end() noexcept
Definition: HashSet.C:479
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
Definition: HashSet.H:191
iterator begin()
Definition: HashSet.C:446
void resize(const label sz)
Resize the hash table for efficiency.
Definition: HashTable.C:601
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
void size(const label n)