Skip to content

Commit

Permalink
using a Set instead of List in UniqueSequence to make it behave properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Zomis committed Jan 4, 2015
1 parent 648e146 commit 38953b2
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public FieldGroup<T> getSmallestFieldGroup() {
@Override
public SimplifyResult simplify(GroupValues<T> knownValues) {
// TODO: Listener for when something is added to knownValues? To be able to detect directly if rule is still OK or not. Likely speed-up.
List<Set<Integer>> setValues = new ArrayList<Set<Integer>>();
Set<Set<Integer>> setValues = new HashSet<Set<Integer>>();
for (List<T> row : list) {
if (!addSet(setValues, row, knownValues)) {
System.out.println("fail");
SimplifyResult result = addSet(setValues, row, knownValues);
if (result.isFailure()) {
return SimplifyResult.FAILED_TOO_BIG_RESULT;
}
}
Expand All @@ -60,7 +60,7 @@ public UniqueSequence<T> copy() {
return new UniqueSequence<T>(getCause(), list);
}

private boolean addSet(List<Set<Integer>> setValues, List<T> row, GroupValues<T> knownValues) {
private SimplifyResult addSet(Set<Set<Integer>> setValues, List<T> row, GroupValues<T> knownValues) {

// loop through row, for each check if it has a value of 1 in the `knownValues`,
// convert the *index*es of the positions to a Set and add to setValues
Expand All @@ -71,13 +71,14 @@ private boolean addSet(List<Set<Integer>> setValues, List<T> row, GroupValues<T>
T pos = it.next();
Integer setValue = getSetValue(pos, knownValues);
if (setValue == null) {
return true;
return SimplifyResult.NO_EFFECT;
}
if (setValue == 1) {
indexSet.add(index);
}
}
return setValues.add(indexSet);
boolean addOK = setValues.add(indexSet);
return addOK ? SimplifyResult.SIMPLIFIED : SimplifyResult.FAILED_NEGATIVE_RESULT;
}

private Integer getSetValue(T pos, GroupValues<T> knownValues) {
Expand Down

0 comments on commit 38953b2

Please sign in to comment.