-
Notifications
You must be signed in to change notification settings - Fork 0
/
TwoBitBimodal.cpp
39 lines (37 loc) · 945 Bytes
/
TwoBitBimodal.cpp
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
#include <string>
#include <iostream>
#include <vector>
#include "TwoBitBimodal.h"
using namespace std;
unsigned long TwoBitBimodal(vector<string> trace, int size){
vector<short> twoBitTable (size,3);
bool result;
unsigned long correct = 0;
unsigned long address;
int index;
string line;
for(int i= 0; i < trace.size(); i++){
line = trace[i];
address = stoul(line.substr(0,10),nullptr, 16);
index = address % size;
result = (line[11] == 'T');
if(twoBitTable[index] > 1 && result){
correct ++;
if(twoBitTable[index] == 2){
twoBitTable[index]++;
}
}
else if(twoBitTable[index]> 1 && !result){
twoBitTable[index]--;
}
else if(twoBitTable[index] < 2 && !result){
correct++;
if(twoBitTable[index] == 1){
twoBitTable[index] --;
}
}else{
twoBitTable[index]++;
}
}
return correct;
}