Ponca  911e152b8d5ac5c934a260b3832f7f62800b65b9
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
13namespace Ponca
14{
15 template <int N, typename T = int>
17 {
19 PONCA_MULTIARCH [[nodiscard]] static constexpr T hash(const int _x)
20 {
21 PONCA_MULTIARCH_STD_MATH(abs);
22 return (abs(_x) * 2654435761u) % N;
23 }
24 };
25
52 template <int N, typename T = int, template <int, typename> typename _HashFunctor = HashDefaultFunctor>
53 class HashSet
54 {
55 static_assert(N > 0, "The capacity must be strictly positive");
57
58 protected:
77 PONCA_MULTIARCH [[nodiscard]] inline bool search(int _value, int& _searchedIdx) const;
78
79 public:
80 constexpr PONCA_MULTIARCH HashSet() : m_data()
81 {
82 // Skip this initialization step if EMPTY is set to 0
83 if constexpr (EMPTY != T(0))
84 {
85 Ponca::internal::fill(m_data, m_data + N, EMPTY);
86 }
87 }
88
93 PONCA_MULTIARCH void clear();
94
107 PONCA_MULTIARCH bool insert(int _value);
108
114 PONCA_MULTIARCH [[nodiscard]] bool contains(int _value) const;
115
116 private:
117 static constexpr T OFFSET =
118 T(1); //< Offsets the value when storing in m_data, to avoid mistaking the stored index value with EMPTY
119 static constexpr T EMPTY = T(0); //< The flag to tell if the address is available or not (Should always be zero)
120 T m_data[N]; //< Where we store the elements in memory
121 };
122} // namespace Ponca
123
124#include "./hashset.hpp"
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:257
Stores unique signed integer values in a contiguous array.
Definition hashset.h:54
bool insert(int _value)
Tries to insert a value in the HashSet.
Definition hashset.hpp:44
bool search(int _value, int &_searchedIdx) const
Search for a value in the HashSet.
Definition hashset.hpp:17
bool contains(int _value) const
Tries to find a value in the HashSet.
Definition hashset.hpp:63
void clear()
Empty the array.
Definition hashset.hpp:11
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
static constexpr T hash(const int _x)
The default hashing function : (abs(x) * 2654435761u) % N.
Definition hashset.h:19