public class NTree extends java.lang.Object implements java.lang.Iterable<DataPoint>
In searching for an element, the mid-point of each branch is used to determine the path through the tree. When the point to be searched is closer than the given tolerance to the midpoint, the other branch is also followed for correctness.
A couple of other standard collections are used to provide efficient index-based access and for reverse lookups of leafs.
Modifier and Type | Field and Description |
---|---|
int |
dimensions
The number of dimensions this structure supports
|
(package private) static int |
MAX
The number of elements to allow in a leaf before splitting
|
Constructor and Description |
---|
NTree(int dimensions)
Constructs an NTree with the given number of dimensions.
|
Modifier and Type | Method and Description |
---|---|
DataPoint |
add(DataPoint point)
Adds a point to the set.
|
void |
addAll(NTree other)
adds all the elements from the given tree to this tree
|
java.util.ArrayList<DataPoint> |
asArrayList()
returns the tree as an arraylist.
|
DataPoint |
get(int index) |
DataPoint |
getClosestPoint(DataPoint point)
Returns the closest point in the tree to the given point.
|
java.util.List<DataPoint> |
getClosestPoints(int number,
DataPoint point)
Gets the closest points to the passed in point.
|
static double |
getDistance(DataPoint a,
DataPoint b)
Determines the Euclidean distance between two points.
|
int |
getIndex(DataPoint point)
Returns the index for the given point.
|
DataPoint |
isUnique(DataPoint point,
double tolerance)
Checks whether the given point already exists in the tree with the
specified tolerance.
|
java.util.Iterator<DataPoint> |
iterator()
Returns an iterator over this tree
|
void |
set(int index,
DataPoint point)
replaces the point at the given index with the one provided.
|
int |
size()
Returns the number of points in the tree.
|
static final int MAX
public final int dimensions
public NTree(int dimensions)
dimensions
- the number of dimensionspublic int size()
public DataPoint add(DataPoint point)
point
- the point to addpublic DataPoint get(int index)
index
- of element to return.public DataPoint isUnique(DataPoint point, double tolerance)
point
- the point to search fortolerance
- the tolerance for determining uniquenesspublic static double getDistance(DataPoint a, DataPoint b)
a
- First point of distanceb
- Second point of distancepublic java.util.List<DataPoint> getClosestPoints(int number, DataPoint point)
number
- the number of points to collectpoint
- the point to find points close topublic DataPoint getClosestPoint(DataPoint point)
point
- public int getIndex(DataPoint point)
point
- the point to lookuppublic java.util.ArrayList<DataPoint> asArrayList()
public void addAll(NTree other)
other
- the other treepublic java.util.Iterator<DataPoint> iterator()
iterator
in interface java.lang.Iterable<DataPoint>
public void set(int index, DataPoint point)
index
- the index to set the point atpoint
- the point to set