commenting and rule application

This commit is contained in:
Florian Steurer 2015-10-24 19:46:51 +02:00
parent 4539faf241
commit 5f9452cfda

View File

@ -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<MPair> applyTypeUnificationRules(Set<MPair> eq, IFiniteClosure fc) {
private LinkedHashSet<MPair> applyTypeUnificationRules(Set<MPair> 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<MPair>
LinkedHashSet<MPair> targetSet = new LinkedHashSet<MPair>();
ArrayList<MPair> 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;
}
}