From 1f55b1bfc39d403345084033cc4cc0be85bca0ac Mon Sep 17 00:00:00 2001 From: Jonny007-MKD <1-23-4-5@web.de> Date: Sun, 5 Jan 2014 19:18:34 +0100 Subject: [PATCH] PrimImplikant mit KV_PiEleLocs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Der PrimImplikant verfügt nun über eine Methode, die die enthaltenen Elemente nach Gray aufsteigend sortiert. Außerdem kann für jedes Element eine KV_PiEleLoc erstellt und in einem Vector abgelegt werden. --- Hazard/Hazard/PrimImplikant.cpp | 30 ++++++++++++++++++++++++-- Hazard/Hazard/PrimImplikant.h | 38 ++++++++++++++++++++++----------- 2 files changed, 54 insertions(+), 14 deletions(-) diff --git a/Hazard/Hazard/PrimImplikant.cpp b/Hazard/Hazard/PrimImplikant.cpp index c9fa0d3..a08275c 100644 --- a/Hazard/Hazard/PrimImplikant.cpp +++ b/Hazard/Hazard/PrimImplikant.cpp @@ -1,5 +1,6 @@ #include "stdafx.h" #include +#include #include #include "PrimImplikant.h" #include "Implikant_localisation.h" @@ -7,7 +8,7 @@ using namespace std; bool PrimImplikant::valueAt(uint pos) { - for (vector::iterator i = implikanten.begin(); i < implikanten.end(); ++i) + for (vector::iterator i = elements.begin(); i < elements.end(); ++i) if (*i == pos) return true; @@ -40,6 +41,31 @@ void PrimImplikant::parser(string input) { // Analyser implikant += (uint)c - (uint)'0'; } - implikanten.push_back(implikant); + elements.push_back(implikant); I_Vector.push_back(new Implikant_localisation(implikant)); +} + +void PrimImplikant::sort() +{ + sort(this->elements.begin(), this->elements.end(), PrimImplikant::compareGray); +} + +bool PrimImplikant::compareGray(uint &a, uint &b) +{ + return (a ^ (a/2)) < (b ^ (b/2)); +} + +void PrimImplikant::makeLocations() +{ + this->sort(); + this->locations = new vector(); + for (uint i = 0; i < this->elements.size(); i++) + this->locations.push_back(new KV_PiEleLoc(this->elements[i])); +} + +vector* locations() +{ + if (this->locations == NULL) + this->makeLocations(); + return this->locations; } \ No newline at end of file diff --git a/Hazard/Hazard/PrimImplikant.h b/Hazard/Hazard/PrimImplikant.h index 50563e8..69d4b40 100644 --- a/Hazard/Hazard/PrimImplikant.h +++ b/Hazard/Hazard/PrimImplikant.h @@ -1,5 +1,4 @@ -#ifndef PRIMIMPLIKANT -#define PRIMIMPLIKANT +#pragma once #include #include @@ -9,9 +8,16 @@ using namespace std; class PrimImplikant { +private: + bool compareGray(uint &a, uint &b); + void makeLocations(); + + vector* locations = NULL; + public: string name; uint id; + vector elements; PrimImplikant(string input) { @@ -42,14 +48,22 @@ public: I_Vector.push_back(new Implikant_localisation(input2)); } - bool PrimImplikant::valueAt(uint position); - void PrimImplikant::parser(string input); - + bool valueAt(uint position); + void parser(string input); + void sort(); + vector* locations(); - - - vector implikanten; - vector I_Vector; - vector*> PI_groupCollection; -}; -#endif \ No newline at end of file + ~PrimImplikant() + { + if (this->locations) + { + for (uint i = 0; i < this->locations.size(); i++) + { + delete this->locations[i]; + this->locations[i] = NULL; + } + delete this->locations; + this->locations = NULL; + } + } +}; \ No newline at end of file