Ponca  911e152b8d5ac5c934a260b3832f7f62800b65b9
Point Cloud Analysis library
Loading...
Searching...
No Matches
bitset.h
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
8#pragma once
9
10#include "../defines.h"
11#include <cstddef>
12#include "./iteratorUtils.h"
13#include "../../Common/Assert.h"
14
15namespace Ponca
16{
40 template <int N, typename T = unsigned long long>
41 class BitSet
42 {
43 static_assert(N > 0, "The capacity must be strictly positive");
44
45 public:
46 PONCA_MULTIARCH BitSet() = default;
47
51 PONCA_MULTIARCH void flip(int i);
52
59 PONCA_MULTIARCH bool erase(int value);
60
68 PONCA_MULTIARCH bool insert(int value);
69
75 PONCA_MULTIARCH [[nodiscard]] bool contains(int value) const;
76
78 PONCA_MULTIARCH void clear();
79
80 protected:
81 static constexpr size_t BIT_SIZE = sizeof(T) * 8;
82 static constexpr size_t ARRAY_SIZE = (N + BIT_SIZE - 1) / BIT_SIZE;
84 };
85} // namespace Ponca
86
87#include "bitset.hpp"
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:257
A simple BitSet implementation that mimics a set of indices.
Definition bitset.h:42
T m_data[ARRAY_SIZE]
An array of bytes.
Definition bitset.h:83
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
static constexpr size_t ARRAY_SIZE
The number of bits in one element of the array.
Definition bitset.h:82
bool contains(int value) const
Search if the value was already inserted or not.
Definition bitset.hpp:45
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition bitset.h:16