1def add_cache(cache: list[dict], block: int, history: int, miss: int) -> tuple:
3 if cache[address].get(block):
4 cache[address][block] = history
6 if len(cache[address]) < 2:
7 cache[address][block] = history
10 assert len(cache[address]) < 3
11 for data
in cache[address]:
13 if cache[address][data] == min(cache[address].values()):
14 del cache[address][data]
15 cache[address][block] = history
22 if cache[address].get(block):
23 cache[address][block] = history
26 cache[address] = {block: history}
33cache = [{}, {}, {}, {}, {}, {}, {}, {}]
34for i
in [
'1',
'2',
'3',
'5',
'6',
'2',
'3',
'4',
'9',
'10',
'11',
'6',
'3',
'6',
'1',
'7',
'8',
'4',
'5',
'9',
'11',
35 '1',
'2',
'4',
'5',
'12',
'13',
'14',
'15',
'13',
'14']:
42cache = [{}, {}, {}, {}]
43for i
in [
'1',
'2',
'3',
'5',
'6',
'2',
'3',
'4',
'9',
'10',
'11',
'6',
'3',
'6',
'1',
'7',
'8',
'4',
'5',
'9',
'11',
44 '1',
'2',
'4',
'5',
'12',
'13',
'14',
'15',
'13',
'14']:
45 cache, miss =
add_cache(cache, int(i), counter, miss)
tuple add_cache(list[dict] cache, int block, int history, int miss)
tuple direct_map_add_cache(list[dict] cache, int block, int history, int miss)