summaryrefslogtreecommitdiffhomepage
path: root/src/handle-page.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-07-12 20:19:25 +0200
committerStanislaw Halik <sthalik@misaki.pl>2024-07-14 13:04:41 +0200
commiteb469ff58365517515d73827e70a9519436b5858 (patch)
tree671a6af202011460ece04359e62ce6b2f87be61f /src/handle-page.hpp
parent679224153849deb04f294f00f19b79102ef1a2d3 (diff)
w
Diffstat (limited to 'src/handle-page.hpp')
-rw-r--r--src/handle-page.hpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/handle-page.hpp b/src/handle-page.hpp
new file mode 100644
index 00000000..dee35a9e
--- /dev/null
+++ b/src/handle-page.hpp
@@ -0,0 +1,40 @@
+#pragma once
+#include "handle-fwd.hpp"
+#include "compat/defs.hpp"
+#include <array>
+#include <cr/BitArray.h>
+
+namespace floormat::Handle {
+
+template<typename Obj, uint32_t PageSize>
+struct Item
+{
+ union { Obj object; };
+ Handle<Obj, PageSize> handle;
+ uint32_t next;
+};
+
+template<typename Obj, uint32_t PageSize>
+class Page
+{
+ friend class Handle<Obj, PageSize>;
+
+ std::array<Item<Obj, PageSize>, PageSize> storage;
+ BitArray used_map; // todo replace with a rewrite of std::bitset
+ uint32_t start_index;
+ uint32_t used_count = 0;
+ uint32_t first_free = (uint32_t)-1;
+
+public:
+ fm_DECLARE_DELETED_COPY_MOVE_ASSIGNMENTS(Page);
+
+ explicit Page(uint32_t start_index);
+ ~Page() noexcept;
+
+ [[nodiscard]] Item<Obj, PageSize>& allocate();
+ void deallocate(Handle<Obj, PageSize> obj);
+ bool is_empty();
+ bool is_full();
+};
+
+} // namespace floormat::Handle