summaryrefslogtreecommitdiff
path: root/src/memory.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/memory.hpp')
-rw-r--r--src/memory.hpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/memory.hpp b/src/memory.hpp
index 83ffd8f..74e72a3 100644
--- a/src/memory.hpp
+++ b/src/memory.hpp
@@ -3,6 +3,7 @@
#include "macros.hpp"
+#include <cstring>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
@@ -43,4 +44,21 @@ inline void PkeDelete(const void *ptr, long count) {
} /* pke */
+uint64_t Buckets_NewHandle(std::size_t bucketBytes, uint64_t bucketItemCount, uint64_t &bucketIncrementer, uint64_t &bucketCounter, uint64_t &itemCounter, void*& buckets);
+
+template <typename T> inline uint64_t Buckets_NewHandle(uint64_t bucketItemCount, uint64_t &bucketIncrementer, uint64_t &bucketCounter, uint64_t &itemCounter, T*& buckets) {
+ void *ptr = reinterpret_cast<void *>(buckets);
+ uint64_t handle = Buckets_NewHandle(sizeof(T), bucketItemCount, bucketIncrementer, bucketCounter, itemCounter, ptr);
+ buckets = reinterpret_cast<T *>(ptr);
+ return handle;
+}
+
+static inline constexpr uint64_t Buckets_GetBucketIndex(uint64_t handle) {
+ return handle & 0x00000000FFFFFFFF;
+}
+
+static inline constexpr uint64_t Buckets_GetItemIndex(uint64_t handle) {
+ return handle >> 32;
+}
+
#endif /* PKE_MEMORY_HPP */