treat null as neutral element for intersection, as it is the default value for uninitialized variables

This commit is contained in:
Juergen Graf 2012-11-30 03:16:17 +01:00
parent 9503100d8b
commit 56780b5076
1 changed files with 18 additions and 4 deletions

View File

@ -21,14 +21,28 @@ public final class BitVectorIntersection extends AbstractMeetOperator<BitVectorV
@Override
public byte evaluate(final BitVectorVariable lhs, final BitVectorVariable[] rhs) {
// as null is the initial value, we treat null as the neutral element to intersection
// which is a set of all possible elements.
IntSet intersect = lhs.getValue();
if (intersect == null || intersect.isEmpty()) {
intersect = rhs[0].getValue();
if (intersect == null) {
for (BitVectorVariable r : rhs) {
intersect = r.getValue();
if (intersect != null) { break; }
}
if (intersect == null) {
// still null - so all rhs is null -> no change
return NOT_CHANGED;
}
} else if (intersect.isEmpty()) {
return NOT_CHANGED_AND_FIXED;
}
for (final BitVectorVariable bv : rhs) {
final IntSet vlhs = bv.getValue();
intersect = intersect.intersection(vlhs);
if (vlhs != null) {
intersect = intersect.intersection(vlhs);
}
}
if (lhs.getValue() != null && intersect.sameValue(lhs.getValue())) {