-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevel.cpp
40 lines (35 loc) · 1.03 KB
/
level.cpp
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
#include "pageTable.h"
// default constructor needed for nextLevel[]
Level::Level()
{
currDepth = 0;
pTable = NULL;
}
// constructor sets depth, pTable, nextLevel and mapPtr
Level::Level(int depth, PageTable* tablePtr)
{
currDepth = depth;
pTable = tablePtr;
setNextLevel();
setNextLevelNull(); // set zeroeth levels netLevel[] to all nulls
mapPtr = nullptr; // initialize to nullptr to avoid segFault.
}
// assigns nextLevel to an array of Level*
void Level::setNextLevel()
{
// size of nextLevel = num possible levels at the currDepth
nextLevel = new Level * [pTable->entryCountArr[currDepth]];
}
// ensures that all elements of nextLevel are set to Null
void Level::setNextLevelNull()
{
for (int i = 0; i < pTable->entryCountArr[currDepth]; i++) {
nextLevel[i] = nullptr;
}
}
// use new operator to assign mapPtr a Map arr
void Level::setMapPtr()
{
// size of mapPtr = num possible levels based on numBits in level
this->mapPtr = new Map[pTable->entryCountArr[currDepth]];
}