forked from kaushal1014/LRU-Cache-Simulation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
35 lines (29 loc) · 772 Bytes
/
Copy pathmain.py
File metadata and controls
35 lines (29 loc) · 772 Bytes
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
r=-1;f=-1
CAHCE_SIZE=5
class LRU:
def __init__(self,size):
self.hit=0
self.miss=0
self.order=[]
self.size=size
def access(self,page):
if page in self.order:
self.hit+=1
self.order.remove(page)
self.order.append(page)
else:
self.miss+=1;
if len(self.order)>=self.size:
self.order.pop(0)
self.order.append(page)
def stats(self):
sum=self.hit+self.miss
if sum>0:
return "Hits:",self.hit,"\n","Hit Rate:",self.hit/sum,"\n","Misses:",self.miss,"\n","Miss Rate:",self.miss/sum
else:
return 0
#testing
chinNIG=LRU(5)
list=[1,1]
for i in list:
chinNIG.access(i)