Ponca  4d2a58fa5c6375adef5c4b208f4d47e016cecd6d
Point Cloud Analysis library
Loading...
Searching...
No Matches
hashset.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 "./iteratorUtils.h"
12#include <utility>
13
14namespace Ponca
15{
16 template <int N, typename T = int>
18 {
20 PONCA_MULTIARCH [[nodiscard]] static constexpr T hash(const int _x)
21 {
22 PONCA_MULTIARCH_STD_MATH(abs);
23 return (abs(_x) * 2654435761u) % N;
24 }
25 };
26
54 template <int N, typename T = int, template <int, typename> typename _HashFunctor = HashDefaultFunctor,
55 T OFFSET = T(1)>
56 class HashSet
57 {
58 static_assert(N > 0, "The capacity must be strictly positive");
60 using container_type = std::array<T, N>;
61 using iterator = typename container_type::iterator;
62 using const_iterator = typename container_type::const_iterator;
64
65 protected:
83 PONCA_MULTIARCH [[nodiscard]] inline bool search(T _value, T& _searchedIdx) const;
84
85 public:
86 constexpr PONCA_MULTIARCH HashSet() : m_data() {}
87
92 PONCA_MULTIARCH void clear();
93
109 PONCA_MULTIARCH std::pair<typename Self::iterator, bool> insert(const T& _value);
110
116 PONCA_MULTIARCH [[nodiscard]] bool contains(T _value) const;
117
118 public:
120 PONCA_MULTIARCH [[nodiscard]] inline Self::const_iterator cbegin() const;
121
123 PONCA_MULTIARCH [[nodiscard]] inline Self::const_iterator cend() const;
124
126 PONCA_MULTIARCH [[nodiscard]] inline Self::iterator begin();
127
129 PONCA_MULTIARCH [[nodiscard]] inline Self::iterator end();
130
131 private:
132 container_type m_data{}; //< Where we store the elements in memory
133 };
134} // namespace Ponca
135
136#include "./hashset.hpp"
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:260
Stores unique signed integer values in a contiguous array.
Definition hashset.h:57
Self::iterator end()
The end of the internal array.
Definition hashset.hpp:30
std::pair< typename Self::iterator, bool > insert(const T &_value)
Tries to insert a value in the HashSet.
Definition hashset.hpp:70
bool contains(T _value) const
Tries to find a value in the HashSet.
Definition hashset.hpp:91
Self::const_iterator cend() const
The end of the internal array.
Definition hashset.hpp:18
Self::iterator begin()
The beginning of the internal array.
Definition hashset.hpp:24
Self::const_iterator cbegin() const
The beginning of the internal array.
Definition hashset.hpp:12
void clear()
Empty the array.
Definition hashset.hpp:37
bool search(T _value, T &_searchedIdx) const
Search for a value in the HashSet.
Definition hashset.hpp:43
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition concepts.h:11
static constexpr T hash(const int _x)
The default hashing function : (abs(x) * 2654435761u) % N.
Definition hashset.h:20