Ponca  82fc77e8c6294111c6f00670e92ec58a24e2ecf2
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 "concepts.h"
12#include "./iteratorUtils.h"
13#include <utility>
14
15namespace Ponca
16{
17 template <int N, typename T = int>
19 {
21 PONCA_MULTIARCH [[nodiscard]] static constexpr T hash(const int _x)
22 {
23 PONCA_MULTIARCH_STD_MATH(abs);
24 return (abs(_x) * 2654435761u) % N;
25 }
26 };
27
55 template <int N, typename T = int, template <int, typename> typename _HashFunctor = HashDefaultFunctor,
56 T OFFSET = T(1)>
57 requires ValidCapacity<N>
58 class HashSet
59 {
60 using HashFunctor = _HashFunctor<N, T>;
61 using container_type = std::array<T, N>;
62 using iterator = typename container_type::iterator;
63 using const_iterator = typename container_type::const_iterator;
65
66 protected:
84 PONCA_MULTIARCH [[nodiscard]] inline bool search(T _value, T& _searchedIdx) const;
85
86 public:
87 constexpr PONCA_MULTIARCH HashSet() : m_data() {}
88
93 PONCA_MULTIARCH void clear();
94
110 PONCA_MULTIARCH std::pair<typename Self::iterator, bool> insert(const T& _value);
111
117 PONCA_MULTIARCH [[nodiscard]] bool contains(T _value) const;
118
119 public:
121 PONCA_MULTIARCH [[nodiscard]] inline Self::const_iterator cbegin() const;
122
124 PONCA_MULTIARCH [[nodiscard]] inline Self::const_iterator cend() const;
125
127 PONCA_MULTIARCH [[nodiscard]] inline Self::iterator begin();
128
130 PONCA_MULTIARCH [[nodiscard]] inline Self::iterator end();
131
132 private:
133 container_type m_data{}; //< Where we store the elements in memory
134 };
135} // namespace Ponca
136
137#include "./hashset.hpp"
Stores unique signed integer values in a contiguous array.
Definition hashset.h:59
std::pair< typename Self::iterator, bool > insert(const T &_value)
Tries to insert a value in the HashSet.
Definition hashset.hpp:77
bool contains(T _value) const
Tries to find a value in the HashSet.
Definition hashset.hpp:99
void clear()
Empty the array.
Definition hashset.hpp:42
Self::const_iterator cend() const
The end of the internal array.
Definition hashset.hpp:20
bool search(T _value, T &_searchedIdx) const
Search for a value in the HashSet.
Definition hashset.hpp:49
Self::iterator end()
The end of the internal array.
Definition hashset.hpp:34
Self::const_iterator cbegin() const
The beginning of the internal array.
Definition hashset.hpp:13
Self::iterator begin()
The beginning of the internal array.
Definition hashset.hpp:27
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:21