Skip to content

Commit

Permalink
Fixed bug in depth first closure calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
DavyLandman committed Jan 12, 2024
1 parent 209ba1d commit 7c173be
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -734,12 +734,13 @@ else if (values instanceof Set) {
throw new IllegalArgumentException("Unexpected map entry");
}
// we mark ourselves as done before we did it,
// so we don't do the <a,a> that causes an extra round
// so we don't do the <a,a> that causes an useless round
done.add(lhs);
IValue rhs;
while ((rhs = todo.poll()) != null) {
boolean rhsFull = done.contains(rhs);
for (IValue composed : result.get(rhs)) {
if (result.__insert(lhs, composed) && !done.contains(composed)) {
if (result.__insert(lhs, composed) && !rhsFull) {
todo.push(composed);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.usethesource.vallang.ExpectedType;
import io.usethesource.vallang.GivenValue;
import io.usethesource.vallang.IList;
import io.usethesource.vallang.IRelation;
import io.usethesource.vallang.ISet;
import io.usethesource.vallang.ISourceLocation;
import io.usethesource.vallang.ITuple;
Expand Down Expand Up @@ -55,7 +56,30 @@ public void transClosureLocs(@ExpectedType("rel[loc,loc]") ISet src) {
assertEquals(src.asRelation().closure().intersect(src), src);
}


@ParameterizedTest @ArgumentsSource(ValueProvider.class)
public void deepClosure(IValueFactory vf) {
IValue prev = vf.integer(0);
var rBuilder = vf.setWriter();
for (int i=1; i < 100; i++) {
IValue next = vf.integer(i);
rBuilder.appendTuple(prev, next);
prev = next;
}
var r = rBuilder.done().asRelation();

assertEquals(slowClosure(vf, r),r.closure(),() -> "Failed with input: " + r.toString());
}

private ISet slowClosure(IValueFactory vf, IRelation<ISet> r) {
var prev = vf.set();
ISet result = r.asContainer();
while (!prev.equals(result)) {
prev = result;
result = result.union( r.compose(result.asRelation()));
}
return result;
}

@ParameterizedTest @ArgumentsSource(ValueProvider.class)
public void carrierForTriples(@ExpectedType("rel[int,int,int]") ISet src) {
ISet carrier = src.asRelation().carrier();
Expand Down

0 comments on commit 7c173be

Please sign in to comment.