From fa42a693748d5f8eaa2fc581309bf56170896f36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Tue, 15 Jan 2019 15:58:39 +0100 Subject: [PATCH] modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java - Hastables fuer greater und smaller eingefuehrt - ? extends/super a <. a = -1 hinzugefuegt --- .../typeinference/unify/TypeUnifyTask.java | 8 ++- .../unify/model/FiniteClosure.java | 57 ++++++++++++++++++- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 64e08376..0ac65b33 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -827,7 +827,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set compRes = fstElemRes.stream().filter(x -> vars_a.contains(((PlaceholderType)x.getLhsType()))).collect(Collectors.toCollection(HashSet::new)); //Alle Variablen bestimmen die nicht hinzugefĆ¼gt wurden in a_last - System.out.println(a_last); + //System.out.println(a_last); a_last.forEach(x -> {writeLog("a_last_elem:" + x + " basepair: " + x.getBasePair());}); List varsLast_a = a_last.stream().filter(x -> ((x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName()) @@ -900,7 +900,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Iterator> nextSetasListIt = new ArrayList>(nextSetasList).iterator(); if (variance == 1) { System.out.println(""); - writeLog("a: " + a.toString()); + writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); while (nextSetasListIt.hasNext()) { Set a_next = nextSetasListIt.next(); if (a.equals(a_next) || @@ -916,7 +916,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } else { if (variance == -1) { System.out.println(""); - writeLog("a: " + a.toString()); + writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); while (nextSetasListIt.hasNext()) { Set a_next = nextSetasListIt.next(); if (a.equals(a_next) || @@ -931,8 +931,10 @@ public class TypeUnifyTask extends RecursiveTask>> { } } else if (variance == 0) { + writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); break; } + writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); } } /* auskommentiert um alle Max und min Betrachtung auszuschalten ENDE */ diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java index f928ea24..07c86457 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -53,6 +53,16 @@ implements IFiniteClosure { */ private Set pairs; + /** + * Hastable fuer die greater-Werte, damit sie nicht doppelt berechnet werden muessen + */ + Hashtable> greaterHash = new Hashtable<>(); + + /** + * Hastable fuer die smaller-Werte, damit sie nicht doppelt berechnet werden muessen + */ + Hashtable> smallerHash = new Hashtable<>(); + /** * Creates a new instance using the inheritance tree defined in the pairs. */ @@ -106,12 +116,29 @@ implements IFiniteClosure { */ @Override public Set smaller(UnifyType type, Set fBounded) { + + Set ret; + if ((ret = smallerHash.get(new hashKeyType(type))) != null) { + //System.out.println(greaterHash); + return new HashSet<>(ret); + } + if(type instanceof FunNType) return computeSmallerFunN((FunNType) type, fBounded); Set>> ts = new HashSet<>(); ts.add(new Pair<>(type, fBounded)); - return computeSmaller(ts); + Set result = computeSmaller(ts); + smallerHash.put(new hashKeyType(type), result); + /* + try { + logFile.write("\ntype: " + type + "\nret: " + ret + "\nresult: " + result);//"smallerHash: " + greaterHash.toString()); + logFile.flush(); + } + catch (IOException e) { + System.err.println("no LogFile"); + }*/ + return result; } /** @@ -205,6 +232,13 @@ implements IFiniteClosure { //Eingefuegt PL 2018-05-24 F-Bounded Problematik public Set greater(UnifyType type, Set fBounded) { + Set ret; + if ((ret = greaterHash.get(new hashKeyType(type))) != null) { + //System.out.println(greaterHash); + return new HashSet<>(ret); + } + + if(type instanceof FunNType) { return computeGreaterFunN((FunNType) type, fBounded); } @@ -300,6 +334,16 @@ implements IFiniteClosure { //System.out.println(""); } } + + greaterHash.put(new hashKeyType(type), result); + /* + try { + logFile.write("\ntype: " + type + "\nret: " + ret + "\nresult: " + result);//"greaterHash: " + greaterHash.toString()); + logFile.flush(); + } + catch (IOException e) { + System.err.println("no LogFile"); + }*/ return result; } @@ -634,8 +678,15 @@ implements IFiniteClosure { return 0; } } - if ((right instanceof PlaceholderType) && (left instanceof WildcardType)) { - return 0; + if (right instanceof PlaceholderType) {//&& (left instanceof WildcardType)) {PL geloescht 2019-01-15 analog zu oben + if ((left instanceof WildcardType) //PL eingefuegt 2019-01-15 analog zu oben + && ((ex = ((WildcardType)left).wildcardedType) instanceof PlaceholderType) + && ((PlaceholderType)right).getName().equals(((PlaceholderType)ex).getName())) {// ? extends a <. a oder ? super a <. a + return 1; + } + else { + return 0; + } } UnifyPair up = new UnifyPair(left, right, pairop); TypeUnifyTask unifyTask = new TypeUnifyTask();