- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCache.java
More file actions
Latest commit
76 lines (66 loc) · 2.53 KB
/
Copy pathCache.java
File metadata and controls
76 lines (66 loc) · 2.53 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* fake cache
* checks for instructions, brings blocks, clears, deletes blocks
*/
classCache {
privateNumb[][] cacheSpots; //2d array of the cache
privateString[] forOutp;
privatelongnumBlocks;
privatelongblockSize;
publicCache(intinstructionSize, intblocks){
numBlocks = blocks;
blockSize = instructionSize;
forOutp = newString[blocks];
cacheSpots = newNumb[blocks][instructionSize];
}
publiclonggetBlockSize(){
return(this.blockSize);
}
publiclonggetNumBlocks(){
returnthis.numBlocks;
}
publicNumbgetCacheSpot(introw,intcol){ //i think i just used this for debugging
returncacheSpots[3][3];
}
publicvoidbringBlock(intblock, Numb[] instructions, intblockOfMM){ //brings a block into mm
for (inti= 0;i<instructions.length;i++){ //populates the correct row of the 2d array of the cache w/ instructions
this.cacheSpots[block][i] = instructions[i];
}
this.forOutp[block] = Integer.toString(blockOfMM); //updates which block is in the mm for the output
}
publicbooleancheckForInstr(intpotentialBlock,intoffset,NumbspecInstr){
booleanthere = false; //to track if instr is in cache or not
if (this.cacheSpots[potentialBlock][offset] != null){ //if something is in this spot
if (this.cacheSpots[potentialBlock][offset].getNumber().equals(specInstr.getNumber())){ //if that "something" is the right instr
there = true;
}
}
returnthere;
}
publicvoidclear(){
for (intb= 0;b<numBlocks;b++){
for (inti= 0;i<blockSize;i++){
cacheSpots[b][i] = null; //make entire 2d array NULLLLLL
}
forOutp[b] = "---"; //changing how it appears in the output
}
}
publicvoiddeleteBlock(intblockNum){
for (inti= 0;i<blockSize;i++){ //deletes the block/row in the cache's 2d array which was meant to be deleted
this.cacheSpots[blockNum][i] = null;
}
this.forOutp[blockNum] = "---"; //change how the output appears
}
publicStringtoString(){ //for printing
StringtoRet = "";
for (Stringspot:forOutp){
if (!(spot == null)){
toRet += (spot + " ");
}
else{
toRet += "____ ";
}
}
returntoRet;
}
}