Package org.tinspin.index.qthypercube
Class QuadTreeRKD<T>
- java.lang.Object
-
- org.tinspin.index.qthypercube.QuadTreeRKD<T>
-
- Type Parameters:
T- Value type.
- All Implemented Interfaces:
Index<T>,RectangleIndex<T>,RectangleIndexMM<T>
public class QuadTreeRKD<T> extends Object implements RectangleIndex<T>, RectangleIndexMM<T>
A simple MX-quadtree implementation with configurable maximum depth, maximum nodes size, and (if desired) automatic guessing of root rectangle.- Author:
- ztilmann
-
-
Field Summary
Fields Modifier and Type Field Description static booleanDEBUG
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclear()Removes all elements from the tree.booleancontains(double[] lower, double[] upper, T value)Lookup an entry, using exact match.booleancontainsExact(double[] keyL, double[] keyU)Check whether a given key exists.static <T> QuadTreeRKD<T>create(int dims)static <T> QuadTreeRKD<T>create(int dims, int maxNodeSize)Deprecated.static <T> QuadTreeRKD<T>create(int dims, int maxNodeSize, double[] center, double radius)static <T> QuadTreeRKD<T>create(int dims, int maxNodeSize, double[] min, double[] max)intgetDepth()intgetDims()intgetNodeCount()protected QRNode<T>getRoot()QuadTreeKD.QStatsgetStats()voidinsert(double[] keyL, double[] keyU, T value)Insert a key-value pair.QueryIterator<RectangleEntry<T>>iterator()List<QREntryDist<T>>knnQuery(double[] center, int k)Deprecated.RectangleEntryDist<T>query1NN(double[] center)Finds the nearest neighbor.TqueryExact(double[] keyL, double[] keyU)Get the value associates with the key.QRIterator<T>queryIntersect(double[] min, double[] max)Query the tree, returning all points in the axis-aligned rectangle between 'min' and 'max'.QueryIteratorKNN<RectangleEntryDist<T>>queryKNN(double[] center, int k)Finds the nearest neighbor.QueryIteratorKNN<RectangleEntryDist<T>>queryKNN(double[] center, int k, RectangleDistanceFunction distFn)Finds the nearest neighbor.QueryIterator<RectangleEntry<T>>queryRectangle(double[] lower, double[] upper)Lookup an entry, using exact match.Tremove(double[] keyL, double[] keyU)Remove a key.booleanremove(double[] lower, double[] upper, T value)Remove *one*n entry with the given value.booleanremoveIf(double[] lower, double[] upper, Predicate<RectangleEntry<T>> condition)Remove *one* entry with the given condition.intsize()Get the number of key-value pairs in the tree.StringtoString()StringtoStringTree()Returns a printable list of the tree.Tupdate(double[] oldKeyL, double[] oldKeyU, double[] newKeyL, double[] newKeyU)Reinsert the key.booleanupdate(double[] oldKeyL, double[] oldKeyU, double[] newKeyL, double[] newKeyU, T value)Update the position of an entry.
-
-
-
Field Detail
-
DEBUG
public static final boolean DEBUG
- See Also:
- Constant Field Values
-
-
Method Detail
-
create
public static <T> QuadTreeRKD<T> create(int dims)
-
create
@Deprecated public static <T> QuadTreeRKD<T> create(int dims, int maxNodeSize)
Deprecated.
-
create
public static <T> QuadTreeRKD<T> create(int dims, int maxNodeSize, double[] min, double[] max)
-
create
public static <T> QuadTreeRKD<T> create(int dims, int maxNodeSize, double[] center, double radius)
-
insert
public void insert(double[] keyL, double[] keyU, T value)Insert a key-value pair.- Specified by:
insertin interfaceRectangleIndex<T>- Specified by:
insertin interfaceRectangleIndexMM<T>- Parameters:
keyL- the lower part of the keykeyU- the upper part of the keyvalue- the value
-
containsExact
public boolean containsExact(double[] keyL, double[] keyU)Check whether a given key exists.- Parameters:
keyL- the lower key to checkkeyU- the upper key to check- Returns:
- true iff the key exists
-
queryExact
public T queryExact(double[] keyL, double[] keyU)
Get the value associates with the key.- Specified by:
queryExactin interfaceRectangleIndex<T>- Parameters:
keyL- the lower key to look upkeyU- the upper key to look up- Returns:
- the value for the key or 'null' if the key was not found
-
contains
public boolean contains(double[] lower, double[] upper, T value)Description copied from interface:RectangleIndexMMLookup an entry, using exact match.- Specified by:
containsin interfaceRectangleIndexMM<T>- Parameters:
lower- minimum cornerupper- maximum cornervalue- the value- Returns:
- `true` if an entry was found, otherwise `false`.
-
queryRectangle
public QueryIterator<RectangleEntry<T>> queryRectangle(double[] lower, double[] upper)
Description copied from interface:RectangleIndexMMLookup an entry, using exact match.- Specified by:
queryRectanglein interfaceRectangleIndexMM<T>- Parameters:
lower- minimum cornerupper- maximum corner- Returns:
- an iterator over all entries at with the exact given rectangle
-
remove
public T remove(double[] keyL, double[] keyU)
Remove a key.- Specified by:
removein interfaceRectangleIndex<T>- Parameters:
keyL- key to removekeyU- key to remove- Returns:
- the value associated with the key or 'null' if the key was not found
-
remove
public boolean remove(double[] lower, double[] upper, T value)Description copied from interface:RectangleIndexMMRemove *one*n entry with the given value.- Specified by:
removein interfaceRectangleIndexMM<T>- Parameters:
lower- minimum cornerupper- maximum cornervalue- value- Returns:
- the value of the entry or null if the entry was not found
-
removeIf
public boolean removeIf(double[] lower, double[] upper, Predicate<RectangleEntry<T>> condition)Description copied from interface:RectangleIndexMMRemove *one* entry with the given condition.- Specified by:
removeIfin interfaceRectangleIndexMM<T>- Parameters:
lower- minimum cornerupper- maximum cornercondition- the condition required for removing an entry- Returns:
- the value of the entry or null if the entry was not found
-
update
public boolean update(double[] oldKeyL, double[] oldKeyU, double[] newKeyL, double[] newKeyU, T value)Description copied from interface:RectangleIndexMMUpdate the position of an entry.- Specified by:
updatein interfaceRectangleIndexMM<T>- Parameters:
oldKeyL- old minoldKeyU- old maxnewKeyL- new minnewKeyU- new maxvalue- only entries with this value are updated- Returns:
- the value, or null if the entries was not found
-
update
public T update(double[] oldKeyL, double[] oldKeyU, double[] newKeyL, double[] newKeyU)
Reinsert the key.- Specified by:
updatein interfaceRectangleIndex<T>- Parameters:
oldKeyL- old keyoldKeyU- old keynewKeyL- new keynewKeyU- new key- Returns:
- the value associated with the key or 'null' if the key was not found.
-
size
public int size()
Get the number of key-value pairs in the tree.
-
clear
public void clear()
Removes all elements from the tree.
-
queryIntersect
public QRIterator<T> queryIntersect(double[] min, double[] max)
Query the tree, returning all points in the axis-aligned rectangle between 'min' and 'max'.- Specified by:
queryIntersectin interfaceRectangleIndex<T>- Specified by:
queryIntersectin interfaceRectangleIndexMM<T>- Parameters:
min- lower left corner of querymax- upper right corner of query- Returns:
- all entries in the rectangle
-
query1NN
public RectangleEntryDist<T> query1NN(double[] center)
Description copied from interface:RectangleIndexFinds the nearest neighbor. This uses euclidean 'edge distance'. Other distance types can only be specified directly on the index implementations.- Specified by:
query1NNin interfaceRectangleIndex<T>- Specified by:
query1NNin interfaceRectangleIndexMM<T>- Parameters:
center- center point- Returns:
- the nearest neighbor
-
knnQuery
@Deprecated public List<QREntryDist<T>> knnQuery(double[] center, int k)
Deprecated.
-
toStringTree
public String toStringTree()
Returns a printable list of the tree.- Specified by:
toStringTreein interfaceIndex<T>- Returns:
- the tree as String
-
getStats
public QuadTreeKD.QStats getStats()
-
getDims
public int getDims()
-
getNodeCount
public int getNodeCount()
- Specified by:
getNodeCountin interfaceIndex<T>
-
iterator
public QueryIterator<RectangleEntry<T>> iterator()
- Specified by:
iteratorin interfaceRectangleIndex<T>- Specified by:
iteratorin interfaceRectangleIndexMM<T>- Returns:
- An iterator over all entries.
-
queryKNN
public QueryIteratorKNN<RectangleEntryDist<T>> queryKNN(double[] center, int k)
Description copied from interface:RectangleIndexFinds the nearest neighbor. This uses euclidean 'edge distance', i.e. the distance to the edge of rectangle. Distance is 0 is the rectangle overlaps with the search point. Other distance types can only be specified directly on the index implementations.- Specified by:
queryKNNin interfaceRectangleIndex<T>- Specified by:
queryKNNin interfaceRectangleIndexMM<T>- Parameters:
center- center pointk- number of neighbors- Returns:
- list of nearest neighbors
-
queryKNN
public QueryIteratorKNN<RectangleEntryDist<T>> queryKNN(double[] center, int k, RectangleDistanceFunction distFn)
Description copied from interface:RectangleIndexMMFinds the nearest neighbor. This uses a custom distance function for distances to rectangles.- Specified by:
queryKNNin interfaceRectangleIndexMM<T>- Parameters:
center- center pointk- number of neighborsdistFn- distance function- Returns:
- list of nearest neighbors
-
-