30 #ifndef SOLIDUTILS_INCLUDE_FIXEDSET_HPP 31 #define SOLIDUTILS_INCLUDE_FIXEDSET_HPP 53 static constexpr T
const NULL_INDEX =
static_cast<T
>(-1);
64 m_index(size, NULL_INDEX)
78 T
const element)
const noexcept
80 size_t const index =
static_cast<size_t>(element);
82 ASSERT_LESS(index, m_index.size());
84 return m_index[index] != NULL_INDEX;
93 T
const element) noexcept
95 size_t const index =
static_cast<size_t>(element);
97 ASSERT_LESS(index, m_index.size());
98 ASSERT_EQUAL(m_index[index], NULL_INDEX);
100 m_data[m_size] = element;
101 m_index[index] = m_size;
113 T
const element) noexcept
115 size_t const index =
static_cast<size_t>(element);
117 ASSERT_LESS(index, m_index.size());
118 ASSERT_NOTEQUAL(m_index[index], NULL_INDEX);
121 T
const swap = m_data[m_size];
122 size_t const place = m_index[index];
123 m_data[place] = swap;
124 m_index[swap] = place;
125 m_index[index] = NULL_INDEX;
136 return m_data.data();
145 T
const *
data() const noexcept
147 return m_data.data();
169 return m_data.begin();
178 T
const *
end() const noexcept
181 return m_data.begin() + m_size;
192 return m_data.begin();
204 return m_data.begin() + m_size;
T * end() noexcept
Get the end iterator (mutable).
Definition: FixedSet.hpp:201
T const * data() const noexcept
Get the underlying array.
Definition: FixedSet.hpp:145
The FixedSet class provides a set implementation which allows for insertion, querying, and deletion in constant time. While std::unordered_set may give constant time complexity of these operations through a hash table, this does so through fixed size dense vector (no hashing).
Definition: FixedSet.hpp:50
T const * begin() const noexcept
Get the beginning iterator.
Definition: FixedSet.hpp:167
FixedSet(size_t const size)
Create a new empty fixed set.
Definition: FixedSet.hpp:60
T * data() noexcept
Get the underlying array.
Definition: FixedSet.hpp:134
size_t size() const noexcept
Get the number of elements in the set.
Definition: FixedSet.hpp:156
The Array class provides functionality similar to std::vector, except that it does not construct or d...
Definition: Array.hpp:53
bool has(T const element) const noexcept
Check if an element exists in this set.
Definition: FixedSet.hpp:77
T * begin() noexcept
Get the beginning iterator (mutable).
Definition: FixedSet.hpp:190
A mutable array structure for storing self-allocated memory.
T const * end() const noexcept
Get the end iterator.
Definition: FixedSet.hpp:178
void add(T const element) noexcept
Add an element to this set.
Definition: FixedSet.hpp:92