Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
ArenaMapKey.h
1// Copyright (c) Stefano Cristiano
2// SPDX-License-Identifier: MIT
3#pragma once
4#include "../Foundation/PrimitiveTypes.h"
5
6namespace SC
7{
8template <typename T>
9struct ArenaMap;
10template <typename T>
11struct ArenaMapKey;
12} // namespace SC
13
16
20template <typename T>
22{
23 private:
24 struct SC_COMPILER_EXPORT Generation
25 {
26 uint32_t used : 1;
27 uint32_t generation : 31;
28 Generation()
29 {
30 used = 0;
31 generation = 0;
32 }
33 bool operator!=(const Generation other) const { return used != other.used or generation != other.generation; }
34 };
35 Generation generation;
36 uint32_t index;
37 friend struct ArenaMap<T>;
38 template <typename U>
39 friend struct ArenaMapKey;
40
41 public:
42 ArenaMapKey() { index = 0; }
43
44 bool isValid() const { return generation.used != 0; }
45
46 template <typename U>
47 ArenaMapKey<U> cast_to()
48 {
50 key.generation.used = generation.used;
51 key.generation.generation = generation.generation;
52 key.index = index;
53 return key;
54 }
55
56 template <typename U>
57 bool operator==(ArenaMapKey<U> other) const
58 {
59 return index == other.index and generation.used == other.generation.used and
60 generation.generation == other.generation.generation;
61 }
62
63 static constexpr uint32_t MaxGenerations = (uint32_t(1) << 31) - 1;
64 static constexpr uint32_t MaxIndex = 0xffffffff;
65};
unsigned int uint32_t
Platform independent (4) bytes unsigned int.
Definition PrimitiveTypes.h:38
A sparse vector keeping objects at a stable memory location.
Definition ArenaMapKey.h:22
A sparse vector keeping objects at a stable memory location.
Definition ArenaMapKey.h:9