Ponca  4d2a58fa5c6375adef5c4b208f4d47e016cecd6d
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 <utility>
13#include "./iteratorUtils.h"
14#include "../../Common/Assert.h"
15
16namespace Ponca
17{
41 template <int N, typename T = unsigned long long>
42 class BitSet
43 {
44 static_assert(N > 0, "The capacity must be strictly positive");
45
46 private:
47 static constexpr size_t BIT_SIZE = sizeof(T) * 8;
48 static constexpr size_t ARRAY_SIZE = (N + BIT_SIZE - 1) / BIT_SIZE;
49 public:
50 using container_type = std::array<T, N>;
51 using iterator = typename container_type::iterator;
52
53 public:
54 PONCA_MULTIARCH BitSet() = default;
55
59 PONCA_MULTIARCH void flip(int i);
60
67 PONCA_MULTIARCH bool erase(int value);
68
81 PONCA_MULTIARCH std::pair<iterator, bool> insert(const int& value);
82
88 PONCA_MULTIARCH [[nodiscard]] bool contains(int value) const;
89
91 PONCA_MULTIARCH void clear();
92
93 PONCA_MULTIARCH [[nodiscard]] iterator begin();
94
95 PONCA_MULTIARCH [[nodiscard]] iterator end();
96
97 protected:
98 container_type m_data = {};
99 };
100} // namespace Ponca
101
102#include "bitset.hpp"
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:260
A simple BitSet implementation that mimics a set of indices.
Definition bitset.h:43
std::pair< iterator, bool > insert(const int &value)
Tries to insert a value in the set.
Definition bitset.hpp:47
void clear()
Sets all the bits to EMPTY.
Definition bitset.hpp:28
container_type m_data
An array of bytes.
Definition bitset.h:98
void flip(int i)
Toggles the value of a bit.
Definition bitset.hpp:71
bool erase(int value)
Tries to insert a value in the set.
Definition bitset.hpp:34
bool contains(int value) const
Search if the value was already inserted or not.
Definition bitset.hpp:59
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition concepts.h:11