-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainMemory.py
35 lines (28 loc) · 1.07 KB
/
MainMemory.py
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
from Page import Page
from Clock import myClock
import logging
logger = logging.getLogger(f"{__name__} thread")
class MainMemory:
def __init__(self, maximumNumberOfPages, K_VALUE, timeOut):
self.mainMemory: list[Page] = []
self.maximumNumberOfPages: int = maximumNumberOfPages
self.K_VALUE = K_VALUE
self.timeOut = timeOut
def full(self):
return len(self.mainMemory) == self.maximumNumberOfPages
def addToMainMemory(self, id: int, value: int):
self.mainMemory.append(Page(id, value, myClock.time, self.K_VALUE))
def getVariable(self, id):
for page in self.mainMemory:
if page.ID == id:
logger.debug(
f"Found page with ID {page.ID} that contains value of {page.value}"
)
return page.value
return -1
def release(self, id):
for page in self.mainMemory:
if page.ID == id:
self.mainMemory.remove(page)
logger.debug(f"Released {page} from main memory")
return