BitOps.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 -------------------------------------------------------------------------------
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 "BitOps.H"
29 #include "bitSet.H"
30 #include "HashSet.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
35 (
36  const label n,
37  const labelHashSet& locations,
38  const bool on
39 )
40 {
41  bitSet output(n, !on);
42 
43  for (const label idx : locations)
44  {
45  // Restrict the input size
46  if (idx < n)
47  {
48  output.set(idx, on);
49  }
50  }
51 
52  return output;
53 }
54 
55 
57 (
58  const label n,
59  const labelUList& locations,
60  const bool on
61 )
62 {
63  bitSet output(n, !on);
64 
65  for (const label idx : locations)
66  {
67  // Restrict the input size
68  if (idx < n)
69  {
70  output.set(idx, on);
71  }
72  }
73 
74  return output;
75 }
76 
77 
79 (
80  const label n,
81  const label select,
82  const labelUList& values,
83  const bool on
84 )
85 {
86  bitSet output(n, !on);
87 
88  // Restrict the input size
89  const label len = std::min(n, values.size());
90 
91  for (label idx = 0; idx < len; ++idx)
92  {
93  if (select == values[idx])
94  {
95  output.set(idx, on);
96  }
97  }
98 
99  return output;
100 }
101 
102 
103 // ************************************************************************* //
BitOps.H
Foam::BitSetOps::create
bitSet create(const label n, const labelHashSet &locations, const bool on=true)
Create a bitSet with length n with the specifed on locations.
Definition: BitOps.C:35
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:64
Foam::HashTableOps::values
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:149
Foam::bitSet::set
void set(const bitSet &bitset)
Set specified bits from another bitset.
Definition: bitSetI.H:563
Foam::HashSet< label, Hash< label > >
bitSet.H
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
HashSet.H
Foam::UList< label >