All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.khelekore.prtree.NearestNeighbour Maven / Gradle / Ivy

There is a newer version: 1.11
Show newest version
package org.khelekore.prtree;

import java.util.PriorityQueue;
import java.util.ArrayList;
import java.util.List;
import org.khelekore.prtree.DistanceResult;
import org.khelekore.prtree.NodeFilter;

class NearestNeighbour {

    private final MBRConverter converter;
    private final NodeFilter filter;
    private final int maxHits;
    private final Node root;
    private final DistanceCalculator dc;
    private final PointND p;

    public NearestNeighbour (MBRConverter converter,
			     NodeFilter filter,
			     int maxHits,
			     Node root,
			     DistanceCalculator dc,
			     PointND p) {
	this.converter = converter;
	this.filter = filter;
	this.maxHits = maxHits;
	this.root = root;
	this.dc = dc;
	this.p = p;
    }

    /**
     * @return the nearest neighbour
     */
    public List> find () {
	List> ret = new ArrayList<> (maxHits);
	MinDistComparator> nc =
	    new MinDistComparator<> (converter, p);
	PriorityQueue> queue = new PriorityQueue<> (20, nc);
	queue.add (root);
	while (!queue.isEmpty ()) {
	    Node n = queue.remove ();
	    n.nnExpand (dc, filter, ret, maxHits, queue, nc);
	}
	return ret;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy