This commit is contained in:
daniel 2017-04-23 19:24:47 -04:00
commit 63211c6c8e
4 changed files with 9 additions and 13 deletions

View File

@ -2,9 +2,7 @@
using namespace std;
AndGate::AndGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
wire* wire3) {
e = eQueue;
AndGate::AndGate(int d, Wire* wire1, Wire* wire2, Wire* wire3) {
delay = d;
in1 = wire1;
in2 = wire2;
@ -13,13 +11,13 @@ AndGate::AndGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
int AndGate::evaluate(int evTime) {
if (in1->getValue(evTime) == 0 || in2->getValue(evTime) == 0) {
if (out->getValue(evTime + delay) != 0) {
e->push(event(e->size, 0, evTime + delay, out));
e->push(Event(e->size, 0, evTime + delay, out));
out->setValue(0, evTime + delay);
}
}
else if(in1->getValue(evTime) == 1 && in2->getValue(evTime) == 1){
if (out->getValue(evTime + delay) != 1) {
e->push(event(e->size, 1, evTime + delay, out));
e->push(Event(e->size, 1, evTime + delay, out));
out->setValue(1, evTime + delay);
}
}

View File

@ -12,13 +12,13 @@ void NandGate::evaluate(int evTime)
{
if (in1->getValue(evTime) == 0 || in2->getValue(evTime) == 0) {
if (out->getValue(evTime + delay) != 1) {
e->push(event(e->size, 1, evTime + delay, out));
e->push(Event(e->size, 1, evTime + delay, out));
out->setValue(1, evTime + delay);
}
}
else {
if (out->getValue(evTime + delay) != 0) {
e->push(event(e->size, 0, evTime + delay, out));
e->push(Event(e->size, 0, evTime + delay, out));
out->setValue(0, evTime + delay);
}
}

View File

@ -3,7 +3,6 @@
using namespace std;
NorGate::NorGate(int d, Wire* wire1, Wire* wire2, Wire* wire3) {
e = eQueue;
delay = d;
in1 = wire1;
in2 = wire2;
@ -13,13 +12,13 @@ NorGate::NorGate(int d, Wire* wire1, Wire* wire2, Wire* wire3) {
void NorGate::evaluate(int evTime) {
if (in1->getValue(evTime) == 1 || in2->getValue(evTime) == 1) {
if (out->getValue(evTime + delay) != 0) {
e->push(event(e->size, 0, evTime + delay, out));
e->push(Event(e->size, 0, evTime + delay, out));
out->setValue(0, evTime + delay);
}
}
else if (in1->getValue(evTime) == 0 && in2->getValue(evTime) == 0) {
if (out->getValue(evTime + delay) != 1) {
e->push(event(e->size, 1, evTime + delay, out));
e->push(Event(e->size, 1, evTime + delay, out));
out->setValue(1, evTime + delay);
}
}

View File

@ -6,19 +6,18 @@ NotGate::NotGate(int d, Wire* wire1, Wire* wire2) {
delay = d;
in1 = wire1;
out = wire2;
}
void NotGate::evaluate(int evTime) {
if (in1->getValue(evTime) == 0) {
if (out->getValue(evTime + delay) != 0) {
e->push(event(e->size, 0, evTime + delay, out));
e->push(Event(e->size, 0, evTime + delay, out));
out->setValue(0, evTime + delay);
}
}
else{
if (out->getValue(evTime + delay) != 1) {
e->push(event(e->size, 1, evTime + delay, out));
e->push(Event(e->size, 1, evTime + delay, out));
out->setValue(1, evTime + delay);
}
}