Search in sources :

Example 1 with ImmutableNode

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));
    }
}
Also used : Function(com.google.common.base.Function) ImmutableNode(io.druid.collections.spatial.ImmutableNode) ImmutablePoint(io.druid.collections.spatial.ImmutablePoint)

Aggregations

Function (com.google.common.base.Function)1 ImmutableNode (io.druid.collections.spatial.ImmutableNode)1 ImmutablePoint (io.druid.collections.spatial.ImmutablePoint)1