-
Notifications
You must be signed in to change notification settings - Fork 0
/
lru.py
43 lines (25 loc) · 856 Bytes
/
lru.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
36
37
38
39
40
41
42
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class LRU:
"""TRABALHO SISTEMAS OPERACIONAIS ABERTOS"""
def execute(self, qtd_quadros, referencias):
pag_falta_mem = 0
inicio = 0
mem = {}
for ref in referencias:
if ref not in mem.keys():
pag_falta_mem += 1
if len(mem) == qtd_quadros:
ant = self.paginaAntiga(mem)
del mem[ant]
mem[ref] = inicio
inicio += 1
return pag_falta_mem
def paginaAntiga(self, mem):
ant = mem.keys()[0]
maisRapido = mem.values()[0]
for ch in mem.keys():
if mem[ch] < maisRapido:
ant = ch
maisRapido = mem[ch]
return ant