diff --git a/src/de/dhbwstuttgart/typeinference/unifynew/Unify.java b/src/de/dhbwstuttgart/typeinference/unifynew/Unify.java index 789feacb6..3158f6e75 100644 --- a/src/de/dhbwstuttgart/typeinference/unifynew/Unify.java +++ b/src/de/dhbwstuttgart/typeinference/unifynew/Unify.java @@ -1,6 +1,11 @@ package de.dhbwstuttgart.typeinference.unifynew; +import java.util.AbstractQueue; +import java.util.ArrayList; import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.Queue; import java.util.Set; import de.dhbwstuttgart.typeinference.Menge; @@ -56,13 +61,58 @@ public class Unify { throw new NotImplementedException(); } - private Set applyTypeUnificationRules(Set eq, IFiniteClosure fc) { + private LinkedHashSet applyTypeUnificationRules(Set eq, IFiniteClosure fc) { - boolean changedInLastIteration = true; + /* + * Strategy for better performance + * + * 1. Erase all erasable rules + * 2. Apply all possible rules to a single pair, then move it to the result set. + * Iterating over pairs first, then iterating over rules prevents the algorithm + * from trying to apply rules to a "finished" pair over and over. + * 2.1 Apply all rules repeatedly except for erase rules. If + * the application of a rule creates new pairs, check immediately + * against the erase rules. + * 2.2 Always use the ordering (IComparable) of the mapped types as the permutation. + * This is saving the time to generate and test permutations. + */ - HashSet + LinkedHashSet targetSet = new LinkedHashSet(); + + ArrayList eqQueue = new ArrayList<>(); + + /* + * Erase all erasable pairs or add them to the queue for further processing + */ + for(MPair pair : eq) + if(!(erase1(pair) || erase2(pair) || erase3(pair))) + eqQueue.add(pair); + + while(!eq.isEmpty()) { + boolean ruleWasApplied = true; + + MPair pair = eqQueue.get(0); + + while(ruleWasApplied) { + ruleWasApplied = false; + + + } + } throw new NotImplementedException(); } + + private boolean erase1(MPair pair) { + return true; + } + + private boolean erase2(MPair pair) { + return true; + } + + private boolean erase3(MPair pair) { + return true; + } }