2#include "gaia/config/config.h"
7#include "gaia/cnt/darray.h"
8#include "gaia/core/utility.h"
9#include "gaia/mem/mem_alloc.h"
17 static constexpr uint32_t PageSize = 1U <<
PageBits;
18 static constexpr uint32_t PageMask = PageSize - 1;
36 pages = GAIA_MOV(other.pages);
41 ~ArchetypeMatchStamps() {
45 GAIA_NODISCARD
bool has(uint32_t sid)
const {
47 return pid <
pages.size() &&
pages[pid] !=
nullptr;
50 GAIA_NODISCARD uint32_t get(uint32_t sid)
const {
51 GAIA_ASSERT(has(sid));
53 const auto did = sid & PageMask;
54 return pages[pid][did];
57 void set(uint32_t sid, uint32_t version) {
59 const auto did = sid & PageMask;
60 auto* page = ensure_page(pid);
65 for (
auto* page:
pages) {
71 std::memset(page, 0,
sizeof(uint32_t) * PageSize);
76 GAIA_NODISCARD uint32_t* ensure_page(uint32_t pid) {
77 if (pid >=
pages.size())
78 pages.resize(pid + 1,
nullptr);
80 auto*& page =
pages[pid];
81 if (page ==
nullptr) {
82 page = mem::AllocHelper::alloc<uint32_t>(
"ArchetypeMatchStampPage", PageSize);
83 std::memset(page, 0,
sizeof(uint32_t) * PageSize);
90 for (
auto* page:
pages) {
93 mem::AllocHelper::free(
"ArchetypeMatchStampPage", page);
Array with variable size of elements of type.
Definition darray_impl.h:25
Checks if endianess was detected correctly at compile-time.
Definition bitset.h:9
Definition query_match_stamps.h:13
cnt::darray< uint32_t * > pages
Lazily allocated pages keyed by archetype id >> PageBits.
Definition query_match_stamps.h:21
void clear()
Definition query_match_stamps.h:64
static constexpr uint32_t PageBits
Keep stamp pages small enough to avoid dense high-water-mark allocations while still preserving O(1) ...
Definition query_match_stamps.h:16