diff --git a/Hazard/Hazard/Cell.cpp b/Hazard/Hazard/Cell.cpp index a41190b..0f059a5 100644 --- a/Hazard/Hazard/Cell.cpp +++ b/Hazard/Hazard/Cell.cpp @@ -4,14 +4,50 @@ #include "PrimImplikantCollection.h" #include "Cell.h" -vector Cell::GetNeighbors() +using namespace std; + +extern uint dimension; + +void Cell::refresh(PrimImplikantCollection* &globalPIC) { - vector neighbors; + this->primImplikanten = globalPIC->primImplikantenAt(index); +} + +vector* Cell::getNeighbors(vector &allCells) +{ + vector* neighbors = new vector(); + + uint j = 1; + for (unsigned char i = 0; i < dimension; i++) + { + neighbors->push_back(allCells[this->index ^ j]); + j <<= 1; + } + return neighbors; } -vector Cell::GetHazards() +vector* Cell::getHazards(vector &allCells) { - vector neighbors; - return neighbors; + vector* hazardous = new vector(); + vector* neighbors = this->getNeighbors(allCells); + + for (vector::iterator neighbor = neighbors->begin(); neighbor < neighbors->end(); neighbor++) + { + if ((*neighbor)->value == false) + continue; + if ((*neighbor)->hasOneOfThose(this->primImplikanten) == false) + hazardous->push_back(*neighbor); + } + + delete neighbors; + return hazardous; +} + +bool Cell::hasOneOfThose(PrimImplikantCollection &foreignPic) +{ + for (uint i = 0; i < foreignPic.size(); i++) + if (this->primImplikanten.contains(foreignPic[i])) + return true; + return false; } \ No newline at end of file diff --git a/Hazard/Hazard/Cell.h b/Hazard/Hazard/Cell.h index 762b9d9..c9f6674 100644 --- a/Hazard/Hazard/Cell.h +++ b/Hazard/Hazard/Cell.h @@ -12,13 +12,15 @@ public: bool value; unsigned int index; - vector GetNeighbors(); // returns numElements Cells - vector GetHazards(); // returns the neighbor Cells which are hazardous + vector* getNeighbors(vector &allCells); // returns numElements Cells + vector* getHazards(vector &allCells); // returns the neighbor Cells which are hazardous + bool hasOneOfThose(PrimImplikantCollection &foreignPIC); + void refresh(PrimImplikantCollection* &globalPIC); // refreshes the local primImplikantCollection Cell(unsigned int index, PrimImplikantCollection* &globalPIC) { this->index = index; - this->primImplikanten = globalPIC->primImplikantenAt(index); + this->refresh(globalPIC); this->value = this->primImplikanten.size() > 0; } diff --git a/Hazard/Hazard/PrimImplikant.h b/Hazard/Hazard/PrimImplikant.h index 25ecb23..4338dc1 100644 --- a/Hazard/Hazard/PrimImplikant.h +++ b/Hazard/Hazard/PrimImplikant.h @@ -10,6 +10,7 @@ class PrimImplikant { public: string name; + uint id; PrimImplikant(string input) { diff --git a/Hazard/Hazard/PrimImplikantCollection.cpp b/Hazard/Hazard/PrimImplikantCollection.cpp index 911c607..f7b7522 100644 --- a/Hazard/Hazard/PrimImplikantCollection.cpp +++ b/Hazard/Hazard/PrimImplikantCollection.cpp @@ -13,17 +13,20 @@ void PrimImplikantCollection::add(PrimImplikant* &PI) void PrimImplikantCollection::add(string input) { PrimImplikant* PI = new PrimImplikant(input); - PIVector.push_back(PI); + PI->id = this->size(); + this->add(PI); } void PrimImplikantCollection::add(uint input) { PrimImplikant* PI = new PrimImplikant(input); - PIVector.push_back(PI); + PI->id = this->size(); + this->add(PI); } void PrimImplikantCollection::add(uint input1, uint input2) { PrimImplikant* PI = new PrimImplikant(input1, input2); - PIVector.push_back(PI); + PI->id = this->size(); + this->add(PI); } bool PrimImplikantCollection::valueAt(uint position) @@ -43,6 +46,14 @@ PrimImplikantCollection PrimImplikantCollection::primImplikantenAt(uint position return pic; } +bool PrimImplikantCollection::contains(PrimImplikant* foreign) +{ + for (vector::iterator i = PIVector.begin(); i < PIVector.end(); i++) + if ((*i)->id == foreign->id) + return true; + return false; +} + uint PrimImplikantCollection::size() { return this->PIVector.size(); diff --git a/Hazard/Hazard/PrimImplikantCollection.h b/Hazard/Hazard/PrimImplikantCollection.h index 77a5dd4..63c8ca7 100644 --- a/Hazard/Hazard/PrimImplikantCollection.h +++ b/Hazard/Hazard/PrimImplikantCollection.h @@ -17,6 +17,7 @@ public: bool valueAt(uint position); PrimImplikantCollection primImplikantenAt(uint position); + bool contains(PrimImplikant* foreign); void Dispose();