Package org.tinspin.index.qtplain
Class QuadTreeRKD0<T>
- java.lang.Object
-
- org.tinspin.index.qtplain.QuadTreeRKD0<T>
-
- Type Parameters:
T- Value type.
- All Implemented Interfaces:
BoxMap<T>,BoxMultimap<T>,Index
public class QuadTreeRKD0<T> extends Object implements BoxMap<T>, BoxMultimap<T>
A simple MX-quadtree implementation with configurable maximum depth, maximum nodes size, and (if desired) automatic guessing of root rectangle.- Author:
- ztilmann
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classQuadTreeRKD0.QRIterator<T>Resetable query iterator.-
Nested classes/interfaces inherited from interface org.tinspin.index.BoxMap
BoxMap.Factory
-
Nested classes/interfaces inherited from interface org.tinspin.index.BoxMultimap
BoxMultimap.Factory
-
Nested classes/interfaces inherited from interface org.tinspin.index.Index
Index.BEComparator, Index.BoxEntry<T>, Index.BoxEntryKnn<T>, Index.BoxFilterKnn<T>, Index.BoxIterator<T>, Index.BoxIteratorKnn<T>, Index.PEComparator, Index.PointEntry<T>, Index.PointEntryKnn<T>, Index.PointFilterKnn<T>, Index.PointIterator<T>, Index.PointIteratorKnn<T>, Index.QueryIterator<T>, Index.QueryIteratorKnn<T>
-
-
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[] min, double[] max)Lookup an entry, using exact match.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> QuadTreeRKD0<T>create(int dims)static <T> QuadTreeRKD0<T>create(int dims, int maxNodeSize)Deprecated.static <T> QuadTreeRKD0<T>create(int dims, int maxNodeSize, double[] center, double radius)static <T> QuadTreeRKD0<T>create(int dims, int maxNodeSize, double[] min, double[] max)intgetDepth()intgetDims()intgetNodeCount()QuadTreeKD0.QStatsgetStats()voidinsert(double[] keyL, double[] keyU, T value)Insert a key-value pair.Index.BoxIterator<T>iterator()Index.BoxEntryKnn<T>query1nn(double[] center)Finds the nearest neighbor.TqueryExact(double[] min, double[] max)Get the value associates with the key.Index.BoxIterator<T>queryExactBox(double[] lower, double[] upper)Lookup an entry, using exact match.QuadTreeRKD0.QRIterator<T>queryIntersect(double[] min, double[] max)Query the tree, returning all points in the axis-aligned rectangle between 'min' and 'max'.QRIteratorKnn<T>queryKnn(double[] center, int k)Finds the nearest neighbor.Index.BoxIteratorKnn<T>queryKnn(double[] center, int k, BoxDistance distFn)Finds the nearest neighbor.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<Index.BoxEntry<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> QuadTreeRKD0<T> create(int dims)
-
create
@Deprecated public static <T> QuadTreeRKD0<T> create(int dims, int maxNodeSize)
Deprecated.
-
create
public static <T> QuadTreeRKD0<T> create(int dims, int maxNodeSize, double[] min, double[] max)
-
create
public static <T> QuadTreeRKD0<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.
-
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[] min, double[] max)
Get the value associates with the key.- Specified by:
queryExactin interfaceBoxMap<T>- Parameters:
min- the lower key to look upmax- 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[] min, double[] max)Description copied from interface:BoxMapLookup an entry, using exact match.
-
contains
public boolean contains(double[] lower, double[] upper, T value)Description copied from interface:BoxMultimapLookup an entry, using exact match.- Specified by:
containsin interfaceBoxMultimap<T>- Parameters:
lower- minimum cornerupper- maximum cornervalue- the value- Returns:
- `true` if an entry was found, otherwise `false`.
-
queryExactBox
public Index.BoxIterator<T> queryExactBox(double[] lower, double[] upper)
Description copied from interface:BoxMultimapLookup an entry, using exact match.- Specified by:
queryExactBoxin interfaceBoxMultimap<T>- Parameters:
lower- minimum cornerupper- maximum corner- Returns:
- an iterator over all entries with the exact given box shape
-
remove
public T remove(double[] keyL, double[] keyU)
Remove a key.
-
remove
public boolean remove(double[] lower, double[] upper, T value)Description copied from interface:BoxMultimapRemove *one*n entry with the given value.- Specified by:
removein interfaceBoxMultimap<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<Index.BoxEntry<T>> condition)Description copied from interface:BoxMultimapRemove *one* entry with the given condition.- Specified by:
removeIfin interfaceBoxMultimap<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:BoxMultimapUpdate the position of an entry.- Specified by:
updatein interfaceBoxMultimap<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.
-
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 QuadTreeRKD0.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 interfaceBoxMap<T>- Specified by:
queryIntersectin interfaceBoxMultimap<T>- Parameters:
min- lower left corner of querymax- upper right corner of query- Returns:
- all entries in the rectangle
-
query1nn
public Index.BoxEntryKnn<T> query1nn(double[] center)
Description copied from interface:BoxMapFinds the nearest neighbor. This uses Euclidean 'edge distance'. Other distance types can only be specified directly on the index implementations.
-
toStringTree
public String toStringTree()
Returns a printable list of the tree.- Specified by:
toStringTreein interfaceIndex- Returns:
- the tree as String
-
getStats
public QuadTreeKD0.QStats getStats()
-
getDims
public int getDims()
-
getNodeCount
public int getNodeCount()
- Specified by:
getNodeCountin interfaceIndex
-
iterator
public Index.BoxIterator<T> iterator()
-
queryKnn
public QRIteratorKnn<T> queryKnn(double[] center, int k)
Description copied from interface:BoxMapFinds the nearest neighbor. This uses Euclidean 'edge distance', i.e. the distance to the edge of a box. Distance is 0 if the box overlaps with the search point. Other distance types can only be specified directly on the index implementations.
-
queryKnn
public Index.BoxIteratorKnn<T> queryKnn(double[] center, int k, BoxDistance distFn)
Description copied from interface:BoxMultimapFinds the nearest neighbor. This uses a custom distance function for distances to boxes.- Specified by:
queryKnnin interfaceBoxMultimap<T>- Parameters:
center- center pointk- number of neighborsdistFn- distance function- Returns:
- list of nearest neighbors
-
-