Ponca  911e152b8d5ac5c934a260b3832f7f62800b65b9
Point Cloud Analysis library
Loading...
Searching...
No Matches
bitset.hpp
1/*
2 This Source Code Form is subject to the terms of the Mozilla Public
3 License, v. 2.0. If a copy of the MPL was not distributed with this
4 file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 \author Auberval Florian
6*/
7
8namespace Ponca
9{
13 template <int N, typename T>
15 {
16 Ponca::internal::fill(m_data, m_data + ARRAY_SIZE, T(0));
17 }
18
19 template <int N, typename T>
20 bool BitSet<N, T>::erase(const int value)
21 {
22 PONCA_ASSERT_MSG(value >= 0 && value < N,
23 "Attempted to remove a value that is outside the scope of the BitSet");
24 const int byte = value / BIT_SIZE;
25 const int bit = value % BIT_SIZE;
26 const T bitMask = (T(1) << bit);
27 const bool alreadyEmpty = (m_data[byte] & bitMask) != 0;
28 m_data[byte] &= ~bitMask;
29 return alreadyEmpty;
30 }
31
32 template <int N, typename T>
34 {
35 PONCA_ASSERT_MSG(value >= 0 && value < N, "Inserted value is outside the scope of the BitSet");
36 const int byte = value / BIT_SIZE;
37 const int bit = value % BIT_SIZE;
38 const T bitMask = (T(1) << bit);
39 const bool alreadyInserted = (m_data[byte] & bitMask) == 0;
40 m_data[byte] |= bitMask;
41 return alreadyInserted;
42 }
43
44 template <int N, typename T>
45 bool BitSet<N, T>::contains(const int value) const
46 {
47 PONCA_ASSERT_MSG(value >= 0 && value < N, "Searched value is outside the scope of the BitSet");
48 const int byte = value / BIT_SIZE;
49 const int bit = value % BIT_SIZE;
50 return (m_data[byte] & (T(1) << bit)) != 0;
51 }
52
56 template <int N, typename T>
57 void BitSet<N, T>::flip(const int i)
58 {
59 PONCA_ASSERT_MSG(i >= 0 && i < N, "Flipped value is outside the scope of the BitSet");
60 const int byte = i / BIT_SIZE;
61 const int bit = i % BIT_SIZE;
62 m_data[byte] ^= (T(1) << bit);
63 }
64} // namespace Ponca
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:257
bool insert(int value)
Tries to insert a value in the set.
Definition bitset.hpp:33
void clear()
Sets all the bits to EMPTY.
Definition bitset.hpp:14
void flip(int i)
Toggles the value of a bit.
Definition bitset.hpp:57
bool erase(int value)
Tries to insert a value in the set.
Definition bitset.hpp:20
bool contains(int value) const
Search if the value was already inserted or not.
Definition bitset.hpp:45
void fill(ForwardIt first, ForwardIt last, const T &value)
Assigns the given value to all elements in the range [first, last).
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition bitset.h:16