From 9ca02c91003eba24731349ced118115e65fc8e26 Mon Sep 17 00:00:00 2001 From: Jonny007-MKD <1-23-4-5@web.de> Date: Mon, 6 Jan 2014 14:56:49 +0100 Subject: [PATCH] Fixed bugs, fixed sorting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Binär -> Gray = X ^ X/2 Gray -> Binär = n-1 times X ^ X/2 --- Hazard/Hazard/PrimImplikant.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Hazard/Hazard/PrimImplikant.cpp b/Hazard/Hazard/PrimImplikant.cpp index a08275c..62933eb 100644 --- a/Hazard/Hazard/PrimImplikant.cpp +++ b/Hazard/Hazard/PrimImplikant.cpp @@ -3,10 +3,12 @@ #include #include #include "PrimImplikant.h" -#include "Implikant_localisation.h" using namespace std; +extern uint dimension; +extern uint numElements; + bool PrimImplikant::valueAt(uint pos) { for (vector::iterator i = elements.begin(); i < elements.end(); ++i) if (*i == pos) @@ -42,30 +44,34 @@ void PrimImplikant::parser(string input) { // Analyser } elements.push_back(implikant); - I_Vector.push_back(new Implikant_localisation(implikant)); } void PrimImplikant::sort() { - sort(this->elements.begin(), this->elements.end(), PrimImplikant::compareGray); + std::sort(this->elements.begin(), this->elements.end(), &PrimImplikant::compareGray); } -bool PrimImplikant::compareGray(uint &a, uint &b) +bool PrimImplikant::compareGray(uint a, uint b) { - return (a ^ (a/2)) < (b ^ (b/2)); + for (uint i = 1; i < dimension; i++) + a ^= a / 2; // convert a from gray to binary + for (uint i = 1; i < dimension; i++) + b ^= b / 2; // convert b from gray to binary + return a < b; } void PrimImplikant::makeLocations() { this->sort(); - this->locations = new vector(); + this->_locations = new vector(); + this->_locations->resize(this->elements.size()); for (uint i = 0; i < this->elements.size(); i++) - this->locations.push_back(new KV_PiEleLoc(this->elements[i])); + (*this->_locations)[i] = new KV_PiEleLoc(this->elements[i]); } -vector* locations() +vector* PrimImplikant::locations() { - if (this->locations == NULL) + if (this->_locations == NULL) this->makeLocations(); - return this->locations; + return this->_locations; } \ No newline at end of file