From 85a15cb256bd9c8922496348e176baf5e947c5b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 13 Feb 2019 18:34:12 +0100 Subject: [PATCH] modified: ../../../../main/java/de/dhbwstuttgart/typeinference/unify/PartialOrderSet.java modified: ../../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java PartialOrderSet als LinkedList realisiert modified: ../../bytecode/javFiles/Matrix.jav --- .../typeinference/unify/PartialOrderSet.java | 36 ++++++++++++------- .../typeinference/unify/TypeUnifyTask.java | 34 +++++++++++------- .../resources/bytecode/javFiles/Matrix.jav | 2 +- 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/PartialOrderSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/PartialOrderSet.java index 53ab6493..52f5734f 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/PartialOrderSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/PartialOrderSet.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; import java.util.Set; import java.util.Vector; @@ -11,8 +13,8 @@ import com.google.common.collect.Ordering; public class PartialOrderSet> implements Set { - HashSet hs = new HashSet<>(); - Vector ve = new Vector<>(); + //HashSet hs = new HashSet<>(); + List ve = new LinkedList<>();//new Vector<>(); F ordering; PartialOrderSet(F ordering) { @@ -23,6 +25,12 @@ public class PartialOrderSet> implements Set { this.ordering= ordering; this.addAll(s); } + + PartialOrderSet(PartialOrderSet pos) { + this.ordering= pos.ordering; + this.ve = new LinkedList<>(pos.ve); + } + @Override public int size() { return ve.size(); @@ -35,7 +43,7 @@ public class PartialOrderSet> implements Set { @Override public boolean contains(Object o) { - return hs.contains(o); + return ve.contains(o); } @Override @@ -57,31 +65,35 @@ public class PartialOrderSet> implements Set { return new ArrayList<>(ve); } + public List toList() { + return new LinkedList<>(ve); + } + @Override public boolean add(E e) { if (this.contains(e)) { return false; } - hs.add(e); + //hs.add(e); for(int i = 0; i< ve.size(); i++) { - if (ordering.compare(e, ve.elementAt(i)) == -1) { - ve.insertElementAt(e, i); + if (ordering.compare(e, ve.get(i)) == -1) { + ve.add(i,e); return true; } } - ve.addElement(e); + ve.add(e); return true; } @Override public boolean remove(Object o) { - hs.remove(o); + //hs.remove(o); return ve.remove(o); } @Override public boolean containsAll(Collection c) { - return hs.containsAll(c); + return ve.containsAll(c); } @Override @@ -97,19 +109,19 @@ public class PartialOrderSet> implements Set { @Override public boolean retainAll(Collection c) { - hs.retainAll(c); + //hs.retainAll(c); return ve.retainAll(c); } @Override public boolean removeAll(Collection c) { - hs.removeAll(c); + //hs.removeAll(c); return ve.removeAll(c); } @Override public void clear() { - hs.clear(); + //hs.clear(); ve.clear(); } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 7eb6408c..77ca34d4 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -571,7 +571,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //PL 2017-10-03 geloest, muesste noch mit FCs mit kleineren //Typen getestet werden. writeLog(nOfUnify.toString() + " Oderconstraints2: " + oderConstraintsOutput.toString()); - if (printtag) System.out.println("secondLevelSets:" +secondLevelSets); + writeLog(nOfUnify.toString() + "secondLevelSets:" +secondLevelSets.toString()); // If pairs occured that did not match one of the cartesian product cases, // those pairs are contradictory and the unification is impossible. if(!undefinedPairs.isEmpty()) { @@ -767,7 +767,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } PartialOrderSet,OrderingUnifyPair> nextSet = remainingSets.remove(0); writeLog("nextSet: " + nextSet.toString()); - List> nextSetasList = nextSet.toArrayList(); + List> nextSetasList = nextSet.toList(); try { //List> //nextSetasList = oup.sortedCopy(nextSet);//new ArrayList<>(nextSet); @@ -930,7 +930,9 @@ public class TypeUnifyTask extends RecursiveTask>> { Set forks = new HashSet<>(); Set newEqOrig = new HashSet<>(eq); Set> newElemsOrig = new HashSet<>(elems); - List,OrderingUnifyPair>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); + //List,OrderingUnifyPair>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); + List,OrderingUnifyPair>> newOderConstraintsOrig = + oderConstraints.stream().map(x -> new PartialOrderSet,OrderingUnifyPair>(x)).collect(Collectors.toList()); newElemsOrig.add(a); /* FORK ANFANG */ @@ -950,7 +952,9 @@ public class TypeUnifyTask extends RecursiveTask>> { } Set newEq = new HashSet<>(eq); Set> newElems = new HashSet<>(elems); - List,OrderingUnifyPair>> newOderConstraints = new ArrayList<>(oderConstraints); + //List,OrderingUnifyPair>> newOderConstraints = new ArrayList<>(oderConstraints); + List,OrderingUnifyPair>> newOderConstraints = + oderConstraints.stream().map(x -> new PartialOrderSet,OrderingUnifyPair>(x)).collect(Collectors.toList()); newElems.add(nSaL); TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, cons); forks.add(fork); @@ -986,7 +990,9 @@ public class TypeUnifyTask extends RecursiveTask>> { Set forks = new HashSet<>(); Set newEqOrig = new HashSet<>(eq); Set> newElemsOrig = new HashSet<>(elems); - List,OrderingUnifyPair>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); + //List,OrderingUnifyPair>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); + List,OrderingUnifyPair>> newOderConstraintsOrig = + oderConstraints.stream().map(x -> new PartialOrderSet,OrderingUnifyPair>(x)).collect(Collectors.toList()); newElemsOrig.add(a); /* FORK ANFANG */ @@ -1006,7 +1012,9 @@ public class TypeUnifyTask extends RecursiveTask>> { } Set newEq = new HashSet<>(eq); Set> newElems = new HashSet<>(elems); - List,OrderingUnifyPair>> newOderConstraints = new ArrayList<>(oderConstraints); + //List,OrderingUnifyPair>> newOderConstraints = new ArrayList<>(oderConstraints); + List,OrderingUnifyPair>> newOderConstraints = + oderConstraints.stream().map(x -> new PartialOrderSet,OrderingUnifyPair>(x)).collect(Collectors.toList()); newElems.add(nSaL); TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, cons); forks.add(fork); @@ -1043,7 +1051,9 @@ public class TypeUnifyTask extends RecursiveTask>> { Set forks = new HashSet<>(); Set newEqOrig = new HashSet<>(eq); Set> newElemsOrig = new HashSet<>(elems); - List,OrderingUnifyPair>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); + //List,OrderingUnifyPair>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); + List,OrderingUnifyPair>> newOderConstraintsOrig = + oderConstraints.stream().map(x -> new PartialOrderSet,OrderingUnifyPair>(x)).collect(Collectors.toList()); newElemsOrig.add(a); /* FORK ANFANG */ @@ -1061,7 +1071,9 @@ public class TypeUnifyTask extends RecursiveTask>> { //nextSetasList.remove(nSaL); Set newEq = new HashSet<>(eq); Set> newElems = new HashSet<>(elems); - List,OrderingUnifyPair>> newOderConstraints = new ArrayList<>(oderConstraints); + //List,OrderingUnifyPair>> newOderConstraints = new ArrayList<>(oderConstraints); + List,OrderingUnifyPair>> newOderConstraints = + oderConstraints.stream().map(x -> new PartialOrderSet,OrderingUnifyPair>(x)).collect(Collectors.toList()); newElems.add(nSaL); TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, cons); forks.add(fork); @@ -2240,8 +2252,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } } - void writeLog(String str) { - synchronized ( this ) { + synchronized void writeLog(String str) { if (log) { try { logFile.write("Thread no.:" + thNo + "\n"); @@ -2254,7 +2265,6 @@ public class TypeUnifyTask extends RecursiveTask>> { catch (IOException e) { System.err.println("kein LogFile"); } - } - } + } } } diff --git a/src/test/resources/bytecode/javFiles/Matrix.jav b/src/test/resources/bytecode/javFiles/Matrix.jav index 9e87c1e6..29505161 100644 --- a/src/test/resources/bytecode/javFiles/Matrix.jav +++ b/src/test/resources/bytecode/javFiles/Matrix.jav @@ -1,6 +1,6 @@ import java.util.Vector; import java.lang.Integer; -//import java.lang.Float; +import java.lang.Float; //import java.lang.Byte; //import java.lang.Boolean;