use of io.druid.collections.spatial.ImmutableNode in project druid by druid-io.
the class GutmanSearchStrategy method breadthFirstSearch.
public Iterable<ImmutableNode> breadthFirstSearch(Iterable<ImmutableNode> nodes, final Bound bound, int total) {
Iterable<ImmutableNode> points = Iterables.concat(Iterables.transform(Iterables.filter(nodes, new Predicate<ImmutableNode>() {
@Override
public boolean apply(ImmutableNode immutableNode) {
return immutableNode.isLeaf();
}
}), new Function<ImmutableNode, Iterable<ImmutableNode>>() {
@Override
public Iterable<ImmutableNode> apply(ImmutableNode immutableNode) {
return Iterables.filter(immutableNode.getChildren(), new Predicate<ImmutableNode>() {
@Override
public boolean apply(ImmutableNode immutableNode) {
return bound.contains(immutableNode.getMinCoordinates());
}
});
}
}));
Iterable<ImmutableNode> overlappingNodes = Iterables.filter(nodes, new Predicate<ImmutableNode>() {
@Override
public boolean apply(ImmutableNode immutableNode) {
return !immutableNode.isLeaf() && bound.overlaps(immutableNode);
}
});
int totalPoints = Iterables.size(points);
int totalOverlap = Iterables.size(overlappingNodes);
if (totalOverlap == 0 || (totalPoints + totalOverlap + total) >= bound.getLimit()) {
return Iterables.concat(points, overlappingNodes);
} else {
return Iterables.concat(points, breadthFirstSearch(Iterables.concat(Iterables.transform(overlappingNodes, new Function<ImmutableNode, Iterable<ImmutableNode>>() {
@Override
public Iterable<ImmutableNode> apply(ImmutableNode immutableNode) {
return immutableNode.getChildren();
}
})), bound, totalPoints));
}
}
Aggregations