コード例 #1
0
  public Queue<List<Double>> findNeighbors(int k, List<Double> point) {

    Queue<List<Double>> pointsN = getPointsQueue(point);
    Queue<BallNode> ballsQueueQ = getBallsQueue(point);
    ballsQueueQ.add(root);

    while (!ballsQueueQ.isEmpty()) {
      BallNode ballS = ballsQueueQ.poll();
      if (pointsN.size() >= k) {
        if (ballS.distanceTo(point) > distance(pointsN.peek(), point)) {
          return pointsN;
        }
      }
      if (ballS.isLeaf()) {
        for (List<Double> p : ballS.points.getData()) {
          pointsN.add(p);
        }
        while (pointsN.size() > k) {
          pointsN.poll();
        }
      } else {
        ballsQueueQ.add(ballS.left);
        ballsQueueQ.add(ballS.right);
      }
    }
    return pointsN;
  }
コード例 #2
0
 public BallTree(Matrix points, int k) {
   root = BallNode.buildBallNode(points, k);
 }