7#include "../utility/utility.hpp"
8#include "../concurrency/concurrency.hpp"
9#include "../macros.hpp"
14#include <unordered_map>
17hi_export_module(hikogui.container.stable_set);
19hi_export
namespace hi::inline
v1 {
34 using value_type = Key;
35 using size_type = size_t;
36 using map_type = std::conditional_t<
41 using difference_type = ptrdiff_t;
42 using reference = value_type
const&;
43 using const_reference = value_type
const&;
44 using pointer = value_type
const *;
45 using const_pointer = value_type
const *;
54 [[nodiscard]]
size_t size()
const noexcept
56 auto const lock = std::scoped_lock(_mutex);
57 return _vector.size();
60 [[nodiscard]]
bool empty()
const noexcept
65 operator bool()
const noexcept
76 [[nodiscard]] const_reference
operator[](
size_t index)
const noexcept
78 auto const lock = std::scoped_lock(_mutex);
79 hi_assert_bounds(index, _vector);
80 return *_vector[index];
92 template<
typename Arg>
93 [[nodiscard]]
size_t insert(Arg&& arg)
noexcept requires(std::is_same_v<std::decay_t<Arg>, value_type>)
95 auto const lock = std::scoped_lock(_mutex);
97 auto const[it, is_inserted] = _map.emplace(std::forward<Arg>(arg), _vector.size());
113 template<
typename... Args>
114 [[nodiscard]]
size_t emplace(Args&&...args)
noexcept
116 auto const lock = std::scoped_lock(_mutex);
118 auto const[it, is_inserted] = _map.emplace(value_type{std::forward<Args>(args)...}, _vector.size());
131 mutable unfair_mutex _mutex;
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
This is a set of object with stable indices.
Definition stable_set.hpp:32
size_t insert(Arg &&arg) noexcept
Insert an object into the stable-set.
Definition stable_set.hpp:93
size_t emplace(Args &&...args) noexcept
Emplace an object into the stable-set.
Definition stable_set.hpp:114
const_reference operator[](size_t index) const noexcept
Get a const reference to an object located at an index in the set.
Definition stable_set.hpp:76