Viskores  1.0
Bitset.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 
19 #ifndef viskores_Bitset_h
20 #define viskores_Bitset_h
21 
22 #include <cassert>
23 #include <limits>
24 #include <viskores/Types.h>
26 
27 namespace viskores
28 {
29 
35 template <typename MaskType>
36 struct Bitset
37 {
39  {
40  this->Mask = static_cast<MaskType>(this->Mask | (static_cast<MaskType>(1) << bitIndex));
41  }
42 
43  VISKORES_EXEC_CONT void set(viskores::Id bitIndex, bool val)
44  {
45  if (val)
46  this->set(bitIndex);
47  else
48  this->reset(bitIndex);
49  }
50 
52  {
53  this->Mask = static_cast<MaskType>(this->Mask & ~(static_cast<MaskType>(1) << bitIndex));
54  }
55 
57  {
58  this->Mask = this->Mask ^ (static_cast<MaskType>(0) << bitIndex);
59  }
60 
61  VISKORES_EXEC_CONT bool test(viskores::Id bitIndex) const
62  {
63  return ((this->Mask & (static_cast<MaskType>(1) << bitIndex)) != 0);
64  }
65 
67  {
68  return this->Mask == otherBitset.Mask;
69  }
70 
71 private:
72  MaskType Mask = 0;
73 };
74 
75 } // namespace viskores
76 
77 #endif //viskores_Bitset_h
Types.h
VISKORES_EXEC_CONT
#define VISKORES_EXEC_CONT
Definition: ExportMacros.h:60
viskores::Bitset::test
bool test(viskores::Id bitIndex) const
Definition: Bitset.h:61
ExportMacros.h
viskores::Bitset::operator==
bool operator==(const viskores::Bitset< MaskType > &otherBitset) const
Definition: Bitset.h:66
viskores::Id
viskores::Int64 Id
Base type to use to index arrays.
Definition: Types.h:235
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::Bitset::set
void set(viskores::Id bitIndex)
Definition: Bitset.h:38
viskores::Bitset::reset
void reset(viskores::Id bitIndex)
Definition: Bitset.h:51
viskores::Bitset
A bitmap to serve different needs.
Definition: Bitset.h:36
viskores::Bitset::set
void set(viskores::Id bitIndex, bool val)
Definition: Bitset.h:43
viskores::Bitset::Mask
MaskType Mask
Definition: Bitset.h:72
viskores::Bitset::toggle
void toggle(viskores::Id bitIndex)
Definition: Bitset.h:56