private void findNN(Node node, ResultSet resultSet, int[] query,
			int[] checks, int maxChecks, PriorityQueue<Branch<Node>> heap,
			BitSet checked) {
		// Terminal node.
		if (node.children.isEmpty()) {
			if (checks[0] >= maxChecks && resultSet.full())
				return;

			for (int i = 0; i < node.points.size(); i++) {
				PointInfo pointInfo = node.points.get(i);
				int index = pointInfo.index;
				if (checked.get(index))
					continue;
				double dist = metric.distance(pointInfo.point, query);
				resultSet.addPoint(dist, index);
				checked.set(index);
				checks[0]++;
			}
		}
		// Internal node.
		else {
			double[] domainDistances = new double[branching];
			domainDistances[0] = metric.distance(query,
					node.children.get(0).pivot);
			int bestIndex = 0;
			for (int i = 1; i < branching; i++) {
				domainDistances[i] = metric.distance(query,
						node.children.get(i).pivot);
				if (domainDistances[i] < domainDistances[bestIndex]) {
					bestIndex = i;
				}
			}

			for (int i = 0; i < branching; i++) {
				if (i != bestIndex) {
					Node child = node.children.get(i);
					heap.add(new Branch<Node>(child, domainDistances[i]));
				}
			}

			findNN(node.children.get(bestIndex), resultSet, query, checks,
					maxChecks, heap, checked);
		}
	}