CommonLibSSE NG
Loading...
Searching...
No Matches
GHash.h
Go to the documentation of this file.
1#pragma once
2
3#include "RE/G/GAllocator.h"
5#include "RE/G/GHashNode.h"
6#include "RE/G/GHashSet.h"
8#include "RE/G/GMemory.h"
9
10namespace RE
11{
12 template <
13 class C,
14 class U,
15 class HashF = GFixedSizeHash<C>,
16 class Allocator = GAllocatorGH<C>,
17 class HashNode = GHashNode<C, U, HashF>,
18 class Entry = GHashsetCachedNodeEntry<HashNode, typename HashNode::NodeHashF>,
19 class Container = GHashSet<HashNode, typename HashNode::NodeHashF, typename HashNode::NodeAltHashF, Allocator, Entry>>
20 class GHash
21 {
22 public:
24 using const_iterator = typename Container::const_iterator;
25 using iterator = typename Container::iterator;
26
28 {}
29
30 GHash(std::int32_t a_sizeHint) :
31 hash(a_sizeHint)
32 {}
33
34 explicit GHash(void* a_heap) :
35 hash(a_heap)
36 {}
37
38 GHash(void* a_heap, std::int32_t a_sizeHint) :
39 hash(a_heap, a_sizeHint)
40 {}
41
42 GHash(const SelfType& a_src) :
43 hash(a_src.hash)
44 {}
45
47 {}
48
49 GFC_MEMORY_REDEFINE_NEW(GHash, Allocator::kStatID);
50
51 void operator=(const SelfType& a_src)
52 {
53 hash = a_src.hash;
54 }
55
56 inline void Clear()
57 {
58 hash.Clear();
59 }
60
61 [[nodiscard]] inline bool IsEmpty() const
62 {
63 return hash.IsEmpty();
64 }
65
66 inline void Set(const C& a_key, const U& a_value)
67 {
68 typename HashNode::NodeRef entry(a_key, a_value);
69 hash.Set(entry);
70 }
71
72 inline void Add(const C& a_key, const U& a_value)
73 {
74 typename HashNode::NodeRef entry(a_key, a_value);
75 hash.Add(entry);
76 }
77
78 inline void Remove(const C& a_key)
79 {
80 hash.RemoveAlt(a_key);
81 }
82
83 template <class K>
84 inline void RemoveAlt(const K& a_key)
85 {
86 hash.RemoveAlt(a_key);
87 }
88
89 bool Get(const C& a_key, U* a_value) const
90 {
91 const HashNode* ptr = hash.GetAlt(a_key);
92 if (ptr) {
93 if (a_value) {
94 *a_value = ptr->second;
95 }
96 return true;
97 }
98 return false;
99 }
100
101 template <class K>
102 bool GetAlt(const K& a_key, U* a_value) const
103 {
104 const HashNode* ptr = hash.GetAlt(a_key);
105 if (ptr) {
106 if (a_value) {
107 *a_value = ptr->second;
108 }
109 return true;
110 }
111 return false;
112 }
113
114 inline U* Get(const C& a_key)
115 {
116 HashNode* ptr = hash.GetAlt(a_key);
117 return ptr ? &ptr->second : nullptr;
118 }
119
120 inline const U* Get(const C& a_key) const
121 {
122 const HashNode* ptr = hash.GetAlt(a_key);
123 return ptr ? &ptr->second : nullptr;
124 }
125
126 template <class K>
127 inline U* GetAlt(const K& a_key)
128 {
129 HashNode* ptr = hash.GetAlt(a_key);
130 return ptr ? &ptr->second : nullptr;
131 }
132
133 template <class K>
134 inline const U* GetAlt(const K& a_key) const
135 {
136 const HashNode* ptr = hash.GetAlt(a_key);
137 return ptr ? &ptr->second : nullptr;
138 }
139
140 [[nodiscard]] inline UPInt GetSize() const
141 {
142 return hash.GetSize();
143 }
144
145 inline void Resize(UPInt a_size)
146 {
147 hash.Resize(a_size);
148 }
149
150 inline void SetCapacity(UPInt a_newSize)
151 {
152 hash.SetCapacity(a_newSize);
153 }
154
156 {
157 return hash.begin();
158 }
159
160 inline iterator end()
161 {
162 return hash.end();
163 }
164
165 inline const_iterator begin() const
166 {
167 return hash.begin();
168 }
169
170 inline const_iterator end() const
171 {
172 return hash.end();
173 }
174
175 iterator Find(const C& a_key)
176 {
177 return hash.FindAlt(a_key);
178 }
179
180 const_iterator Find(const C& a_key) const
181 {
182 return hash.FindAlt(a_key);
183 }
184
185 template <class K>
186 iterator FindAlt(const K& a_key)
187 {
188 return hash.FindAlt(a_key);
189 }
190
191 template <class K>
192 const_iterator FindAlt(const K& a_key) const
193 {
194 return hash.FindAlt(a_key);
195 }
196
197 // members
199 };
200}
Definition GHash.h:21
void Set(const C &a_key, const U &a_value)
Definition GHash.h:66
const U * GetAlt(const K &a_key) const
Definition GHash.h:134
const U * Get(const C &a_key) const
Definition GHash.h:120
iterator begin()
Definition GHash.h:155
U * Get(const C &a_key)
Definition GHash.h:114
const_iterator FindAlt(const K &a_key) const
Definition GHash.h:192
GHash(std::int32_t a_sizeHint)
Definition GHash.h:30
void SetCapacity(UPInt a_newSize)
Definition GHash.h:150
bool Get(const C &a_key, U *a_value) const
Definition GHash.h:89
GHash(const SelfType &a_src)
Definition GHash.h:42
void RemoveAlt(const K &a_key)
Definition GHash.h:84
~GHash()
Definition GHash.h:46
GHash(void *a_heap)
Definition GHash.h:34
bool GetAlt(const K &a_key, U *a_value) const
Definition GHash.h:102
typename Container::const_iterator const_iterator
Definition GHash.h:24
typename Container::iterator iterator
Definition GHash.h:25
iterator Find(const C &a_key)
Definition GHash.h:175
const_iterator begin() const
Definition GHash.h:165
void Resize(UPInt a_size)
Definition GHash.h:145
GFC_MEMORY_REDEFINE_NEW(GHash, Allocator::kStatID)
void operator=(const SelfType &a_src)
Definition GHash.h:51
GHash()
Definition GHash.h:27
U * GetAlt(const K &a_key)
Definition GHash.h:127
void Clear()
Definition GHash.h:56
GHash(void *a_heap, std::int32_t a_sizeHint)
Definition GHash.h:38
iterator end()
Definition GHash.h:160
void Remove(const C &a_key)
Definition GHash.h:78
const_iterator end() const
Definition GHash.h:170
iterator FindAlt(const K &a_key)
Definition GHash.h:186
UPInt GetSize() const
Definition GHash.h:140
bool IsEmpty() const
Definition GHash.h:61
void Add(const C &a_key, const U &a_value)
Definition GHash.h:72
const_iterator Find(const C &a_key) const
Definition GHash.h:180
Container hash
Definition GHash.h:198
Definition AbsorbEffect.h:6
std::size_t UPInt
Definition SFTypes.h:5