2
3
4
5
8#include "Core/Memory/MemoryPool.h"
9#include "Core/Memory/ObjectPool.h"
14
15
16
17
18 template<size_t BITS, size_t LAYER>
22
23
24
26 class radix_trie<BITS, 1>
31
32
36
37
44
45
51
52
59
60
70
71
72
73
74 void*
get(size_t k)
const
81 return m_Root->values[k];
85
86
87
88
89 void set(size_t k,
void* v)
91 assert(k >> BITS == 0);
93 m_Root->values[k] = v;
98
99
100
101 template<size_t BITS>
102 class radix_trie<BITS, 2>
107
108
112
113
117
118
122
123
127
128
135
136
143
144
148
149
155
156
164
165
175
176
177
178
181 const size_t i1 = k >> LEAF_BITS;
182 const size_t i2 = k & (LEAF_LENGTH - 1 );
184 if ((k >> BITS) > 0 || m_Root->ptrs[i1] ==
nullptr)
189 return reinterpret_cast<Leaf*>(m_Root->ptrs[i1])->values[i2];
193
194
195
196
197 void set(size_t k,
void* v)
199 assert(k >> BITS == 0);
201 const size_t i1 = k >> LEAF_BITS;
202 const size_t i2 = k & (LEAF_LENGTH - 1);
204 assert(i1 < ROOT_LENGTH);
205 assert(i2 < LEAF_LENGTH);
207 if (!m_Root->ptrs[i1])
209 m_Root->ptrs[i1] =
reinterpret_cast<Node*>(m_LeafPool.New());
212 reinterpret_cast<Leaf*>(m_Root->ptrs[i1])->values[i2] = v;
217
218
219
220 template<size_t BITS>
221 class radix_trie<BITS, 3>
226
227
231
232
236
237
241
242
246
247
254
255
262
263
267
268
272
273
279
280
289
290
294
295
296
297
300 const size_t i1 = k >> (LEAF_BITS + INTERIOR_BITS);
301 const size_t i2 = (k >> LEAF_BITS) & (INTERIOR_LENGTH - 1);
302 const size_t i3 = k & (LEAF_LENGTH - 1);
304 if((k >> BITS) || m_Root->ptrs[i1] ==
nullptr || m_Root->ptrs[i1]->ptrs[i2] ==
nullptr)
309 return reinterpret_cast<Leaf*>(m_Root->ptrs[i1]->ptrs[i2])->values[i3];
313
314
315
316
317 void set(size_t k,
void* v)
319 assert(k >> BITS == 0);
321 const size_t i1 = k >> (LEAF_BITS + INTERIOR_BITS);
322 const size_t i2 = (k >> LEAF_BITS) & (INTERIOR_LENGTH - 1);
323 const size_t i3 = k & (LEAF_LENGTH - 1);
325 assert(i1 < INTERIOR_LENGTH);
326 assert(i2 < INTERIOR_LENGTH);
327 assert(i3 < LEAF_LENGTH);
329 if (!m_Root->ptrs[i1])
331 m_Root->ptrs[i1] = m_NodePool.New();
334 if (!m_Root->ptrs[i1]->ptrs[i2])
336 m_Root->ptrs[i1]->ptrs[i2] =
reinterpret_cast<Node*>(m_LeafPool.New());
339 reinterpret_cast<Leaf*>(m_Root->ptrs[i1]->ptrs[i2])->values[i3] = v;
CentralCache()=default
Constructor Function.
static scl::span * GetOneSpan(scl::span_list &list, size_t size)
Get a not empty span.
size_t FetchRange(void *&start, void *&end, size_t batchNum, size_t size)
Fetch range memory to tc.
static CentralCache m_CentralCache
Single instance of this.
CentralCache & operator=(const CentralCache &)=delete
Copy Assignment Operation.
virtual ~CentralCache()=default
Destructor Function.
void ReleaseListToSpans(void *start, size_t size)
Release memory to pc.
std::array< scl::span_list, MemoryPool::FREE_LIST_NUM > m_SpanLists
FreeList Array.
CentralCache(const CentralCache &)=delete
Copy Constructor Function.
static CentralCache * Get()
Get this single Instance.
Central memory cache. Second level of memory allocator.
static void *& PointerSpace(void *obj)
Get object first 4/8 bytes as a pointer.
ObjectPool Class. Specific situation(Fixed size of block) of MemoryPool.
scl::radix_trie< 64 - MemoryPool::PAGE_SHIFT, 3 > m_IdSpanMap
radix trie for [pageId - span]
virtual ~PageCache()=default
Destructor Function.
PageCache & operator=(const PageCache &)=delete
Copy Assignment Operation.
static PageCache m_PageCache
this single instance.
PageCache()=default
Constructor Function.
scl::span * MapObjectToSpan(void *obj) const
Find span by memory pointer.
scl::span * InternalNewSpan(size_t k)
Fetch pages span(internal call).
static PageCache * Get()
Get this single instance.
void ReleaseSpanToPageCache(scl::span *s)
Release span from cc to pc,.
std::mutex m_Mutex
mutex for pc.
scl::span * NewSpan(size_t k)
Fetch pages span.
ObjectPool< scl::span > m_SpanPool
ObjectPool for span.
PageCache(const PageCache &)=delete
Copy Constructor Function.
std::array< scl::span_list, MemoryPool::PAGE_NUM > m_SpanLists
FreeList Array.
Page memory cache. Third level of memory allocator.
radix_trie()
Constructor Function.
void * get(size_t k) const
Get item by key.
static constexpr size_t LENGTH
array length.
void set(size_t k, void *v)
Set pair of key - value.
virtual ~radix_trie()
Deconstruct Function.
virtual ~radix_trie()
Deconstruct Function.
void * get(size_t k) const
Get item by key.
static constexpr size_t ROOT_BITS
root bits.
static constexpr size_t LEAF_BITS
leaf bits.
radix_trie()
Constructor Function.
void set(size_t k, void *v)
Set pair of key - value.
static constexpr size_t LEAF_LENGTH
leaf array length.
Spices::ObjectPool< Leaf > m_LeafPool
ObjectPool of Leaf.
static constexpr size_t ROOT_LENGTH
root array length.
static constexpr size_t LEAF_LENGTH
leaf array length.
radix_trie()
Constructor Function.
void * get(size_t k) const
Get item by key.
void set(size_t k, void *v)
Set pair of key - value.
virtual ~radix_trie()=default
Deconstruct Function.
static constexpr size_t INTERIOR_LENGTH
interior array length.
Spices::ObjectPool< Leaf > m_LeafPool
ObjectPool of Leaf.
static constexpr size_t INTERIOR_BITS
interior bits.
Spices::ObjectPool< Node > m_NodePool
ObjectPool of Node.
static constexpr size_t LEAF_BITS
leaf bits.
void PushFront(span *s)
Push a span to this list.
span * Begin() const
Get begin pointer.
span * End() const
Get end pointer.
Bidirectional cyclic linked list for span.
void * m_FreeList
current pointer.
bool m_IsUse
True if in use.
Used for manage multiple page memory.
ObjectPoolSizeMode
enum of ObjectPool expand mode
std::array< void *, LENGTH > values
std::array< void *, LEAF_LENGTH > values
std::array< Node *, ROOT_LENGTH > ptrs
std::array< void *, LEAF_LENGTH > values
std::array< Node *, INTERIOR_LENGTH > ptrs