-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaged_array.hpp
45 lines (36 loc) · 902 Bytes
/
paged_array.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef VI_PAGED_ARRAY_HPP
#define VI_PAGED_ARRAY_HPP
#include "memory_block.hpp"
namespace vi
{
template<class T, uint32_t ElementCount, uint32_t PageSize>
class paged_array
{
private:
memory_block<memory_block<T, PageSize>, ElementCount / PageSize + 1> mPages;
public:
paged_array()
{
assert(ElementCount > 0);
assert(PageSize > 0);
}
void zero_fill()
{
for(uint32_t i = 0; i < mPages.size(); ++i)
{
mPages[i].zero_fill();
}
}
uint32_t size() const
{
return ElementCount;
}
T& operator[](uint32_t index)
{
uint32_t pageIndex = index / PageSize;
uint32_t indexInPage = index % PageSize;
return mPages[pageIndex][indexInPage];
}
};
};
#endif