18template<
typename T = std::u
int64_t,
typename A = std::allocator<T>>
22 using allocator_type = A;
23 using storage_type = std::vector<block_type, allocator_type>;
28 explicit dynamic_bitset(std::size_t initial_blocks = 1) {
29 _blocks.resize(initial_blocks);
37 [[nodiscard]]
inline auto test(std::size_t pos)
const noexcept ->
bool {
38 const auto [block_index, bit_pos] = block_and_bit(pos);
39 if (block_index < _blocks.size()) {
40 return _blocks[block_index] & (block_type{ 1 } << bit_pos);
50 inline auto set(std::size_t pos,
bool value =
true) -> dynamic_bitset& {
51 const auto [block_index, bit_pos] = block_and_bit(pos);
52 if (block_index >= _blocks.size()) {
53 _blocks.resize(block_index + 1);
56 _blocks[block_index] |= (block_type{ 1 } << bit_pos);
58 _blocks[block_index] &= ~(block_type{ 1 } << bit_pos);
60 std::size_t i = _blocks.size() - 1;
61 while (!_blocks[i] && i != 0) {
64 _blocks.resize(i + 1);
70 inline void clear() noexcept {
80 auto operator==(
const dynamic_bitset& rhs)
const noexcept ->
bool {
81 return std::ranges::equal(_blocks, rhs._blocks);
85 friend struct std::hash<dynamic_bitset>;
87 static inline auto block_and_bit(std::size_t pos) -> std::pair<std::size_t, std::size_t> {
88 const auto bit_pos = pos % (
sizeof(block_type) * CHAR_BIT);
89 const auto block_index = pos / (
sizeof(block_type) * CHAR_BIT);
90 return std::make_pair(block_index, bit_pos);
102struct hash<
co_ecs::detail::dynamic_bitset<A>> {
103 auto operator()(
const co_ecs::detail::dynamic_bitset<A>& bitset)
const -> std::size_t {
104 std::size_t hash = 0;
105 for (
auto block : bitset._blocks) {
Definition component.hpp:17
Definition archetype.hpp:11
constexpr bool operator==(const co_ecs::detail::temp_allocator< T > &, const co_ecs::detail::temp_allocator< U > &) noexcept
Definition temp_allocator.hpp:60