This commit is contained in:
Joel Beckmeyer 2017-04-23 20:30:52 -04:00
commit 4a5e49f8d6
2 changed files with 14 additions and 9 deletions

View File

@ -7,22 +7,26 @@ Wire::Wire(int number, bool io, string inName)
name = inName; name = inName;
value = -1; value = -1;
lastEvent = 0; lastEvent = 0;
history.insert(history.begin(), 60, -1);
} }
int Wire::getValue(int time) const int Wire::getValue(int wantedTime) const
{ {
for (auto i = history.begin() + time; i != history.begin(); i--) { if (historyTimes.size() == 0 || wantedTime < historyTimes[0]) {
if (i[0] != -1) { return -1;
return i[0]; }
else {
for (auto i = historyTimes.begin(); i != historyTimes.end(); i++) {
if (*i > wantedTime) {
return historyValues[i - 1 - historyTimes.begin()];
}
} }
} }
return -1;
} }
void Wire::setValue(int newValue, int setTime) void Wire::setValue(int newValue, int setTime)
{ {
history[setTime] = newValue; historyTimes.push_back(setTime);
historyValues.push_back(newValue);
if (lastEvent < setTime) { if (lastEvent < setTime) {
lastEvent = setTime; lastEvent = setTime;
} }

View File

@ -15,7 +15,7 @@ class Wire {
void addGate(Gate* newGate); void addGate(Gate* newGate);
int getValue(int time) const; int getValue(int wantedTime) const;
int getNumber() const; int getNumber() const;
string getName() const; string getName() const;
@ -23,7 +23,8 @@ class Wire {
private: private:
int WireNumber, value, lastEvent; int WireNumber, value, lastEvent;
vector<int> history; vector<int> historyTimes;
vector<int> historyValues;
string name; string name;
bool isPrint; bool isPrint;
vector<Gate*> gates; vector<Gate*> gates;