stellarlib 0.1.0
Loading...
Searching...
No Matches
sparse_set.hpp
1/* clang-format off */
2
3/*
4 stellarlib
5 Copyright (C) 2025-2026 Domán Zana
6
7 This software is provided 'as-is', without any express or implied
8 warranty. In no event will the authors be held liable for any damages
9 arising from the use of this software.
10
11 Permission is granted to anyone to use this software for any purpose,
12 including commercial applications, and to alter it and redistribute it
13 freely, subject to the following restrictions:
14
15 1. The origin of this software must not be misrepresented; you must not
16 claim that you wrote the original software. If you use this software
17 in a product, an acknowledgment in the product documentation would be
18 appreciated but is not required.
19 2. Altered source versions must be plainly marked as such, and must not be
20 misrepresented as being the original software.
21 3. This notice may not be removed or altered from any source distribution.
22*/
23
24#ifndef STELLARLIB_ECS_SPARSE_SET_HPP
25#define STELLARLIB_ECS_SPARSE_SET_HPP
26
27#include <stellarlib/ecs/stack_vector.hpp>
28
29#include <cstdint>
30
31namespace stellarlib::ecs::internal
32{
33class sparse_set final
34{
35public:
36 [[nodiscard]]
37 sparse_set() noexcept;
38
39 [[nodiscard]]
40 constexpr sparse_set(const sparse_set &) noexcept = delete;
41
42 [[nodiscard]]
43 sparse_set(sparse_set &&) noexcept;
44
45 constexpr auto operator=(const sparse_set &) noexcept
46 -> sparse_set & = delete;
47
48 auto operator=(sparse_set &&) noexcept
49 -> sparse_set &;
50
51 ~sparse_set() noexcept;
52
53 void insert(std::uint32_t key) noexcept;
54
55 [[nodiscard]]
56 auto size() const noexcept
57 -> std::uint32_t;
58
59 [[nodiscard]]
60 auto contains(std::uint32_t key) const noexcept
61 -> bool;
62
63 [[nodiscard]]
64 auto begin() const noexcept
65 -> const std::uint32_t *;
66
67 [[nodiscard]]
68 auto end() const noexcept
69 -> const std::uint32_t *;
70
71 void erase(std::uint32_t key) noexcept;
72
73 void clear() noexcept;
74
75private:
76 stack_vector<std::uint32_t, std::uint32_t> _sparse;
77 stack_vector<std::uint32_t, std::uint32_t> _keys;
78};
79}
80
81#endif