Package org.tinspin.index.qtplain
Class QuadTreeKD0<T>
- java.lang.Object
-
- org.tinspin.index.qtplain.QuadTreeKD0<T>
-
- Type Parameters:
T- Value type.
- All Implemented Interfaces:
Index,PointMap<T>,PointMultimap<T>
public class QuadTreeKD0<T> extends Object implements PointMap<T>, PointMultimap<T>
A simple MX-quadtree implementation with configurable maximum depth, maximum nodes size, and (if desired) automatic guessing of root rectangle.This version of the quadtree stores for each node only the center point and the distance (radius) to the edges. This reduces space requirements but increases problems with numerical precision. Overall it is more space efficient and slightly faster.
- Author:
- ztilmann
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classQuadTreeKD0.QIterator<T>Resettable query iterator.static classQuadTreeKD0.QStatsStatistics container class.-
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>
-
Nested classes/interfaces inherited from interface org.tinspin.index.PointMap
PointMap.Factory
-
Nested classes/interfaces inherited from interface org.tinspin.index.PointMultimap
PointMultimap.Factory
-
-
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[] key)Deprecated.booleancontains(double[] key, T value)Lookup an entry, using exact match.static <T> QuadTreeKD0<T>create(int dims)static <T> QuadTreeKD0<T>create(int dims, int maxNodeSize)static <T> QuadTreeKD0<T>create(int dims, int maxNodeSize, double[] center, double radius)intgetDepth()intgetDims()intgetNodeCount()QuadTreeKD0.QStatsgetStats()voidinsert(double[] key, T value)Insert a key-value pair.Index.PointIterator<T>iterator()QuadTreeKD0.QIterator<T>query(double[] min, double[] max)Query the tree, returning all points in the axis-aligned rectangle between 'min' and 'max'.Index.PointEntryKnn<T>query1nn(double[] center)Finds the nearest neighbor.TqueryExact(double[] key)Get the value associates with the key.Index.PointIterator<T>queryExactPoint(double[] point)Lookup an entries at a given coordinate.Index.PointIteratorKnn<T>queryKnn(double[] center, int k)Finds the nearest neighbor.Index.PointIteratorKnn<T>queryKnn(double[] center, int k, PointDistance dist)Finds the nearest neighbor.Tremove(double[] key)Remove a key.booleanremove(double[] key, T value)Remove *one* entry with the given value.booleanremoveIf(double[] key, Predicate<Index.PointEntry<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[] oldKey, double[] newKey)Reinsert the key.booleanupdate(double[] oldKey, double[] newKey, T value)Reinsert the key.TupdateIf(double[] oldKey, double[] newKey, Predicate<Index.PointEntry<T>> condition)Reinsert the key.
-
-
-
Field Detail
-
DEBUG
public static final boolean DEBUG
- See Also:
- Constant Field Values
-
-
Method Detail
-
create
public static <T> QuadTreeKD0<T> create(int dims)
-
create
public static <T> QuadTreeKD0<T> create(int dims, int maxNodeSize)
-
create
public static <T> QuadTreeKD0<T> create(int dims, int maxNodeSize, double[] center, double radius)
-
insert
public void insert(double[] key, T value)Insert a key-value pair.
-
contains
@Deprecated public boolean contains(double[] key)
Deprecated.Check whether a given key exists.
-
queryExact
public T queryExact(double[] key)
Get the value associates with the key.- Specified by:
queryExactin interfacePointMap<T>- Parameters:
key- the key to look up- Returns:
- the value for the key or 'null' if the key was not found
-
contains
public boolean contains(double[] key, T value)Description copied from interface:PointMultimapLookup an entry, using exact match.- Specified by:
containsin interfacePointMultimap<T>- Parameters:
key- the pointvalue- the value- Returns:
- `true` if an entry was found, otherwise `false`.
-
remove
public T remove(double[] key)
Remove a key.
-
remove
public boolean remove(double[] key, T value)Description copied from interface:PointMultimapRemove *one* entry with the given value.- Specified by:
removein interfacePointMultimap<T>- Parameters:
key- the pointvalue- only entries with this value are removed- Returns:
- the value of the entry or null if the entry was not found
-
removeIf
public boolean removeIf(double[] key, Predicate<Index.PointEntry<T>> condition)Description copied from interface:PointMultimapRemove *one* entry with the given condition.- Specified by:
removeIfin interfacePointMultimap<T>- Parameters:
key- the pointcondition- the condition required for removing an entry- Returns:
- the value of the entry or null if the entry was not found
-
update
public T update(double[] oldKey, double[] newKey)
Reinsert the key.
-
update
public boolean update(double[] oldKey, double[] newKey, T value)Reinsert the key.- Specified by:
updatein interfacePointMultimap<T>- Parameters:
oldKey- old keynewKey- new keyvalue- the value of the entry that should be updated.- Returns:
- the value associated with the key or 'null' if the key was not found.
-
updateIf
public T updateIf(double[] oldKey, double[] newKey, Predicate<Index.PointEntry<T>> condition)
Reinsert the key.- Parameters:
oldKey- old keynewKey- new keycondition- A predicate that must evaluate to 'true' for an entry to be updated.- 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.
-
queryExactPoint
public Index.PointIterator<T> queryExactPoint(double[] point)
Description copied from interface:PointMultimapLookup an entries at a given coordinate.- Specified by:
queryExactPointin interfacePointMultimap<T>- Parameters:
point- the point- Returns:
- an iterator over all entries at the given coordinate.
- See Also:
PointMultimap.queryExactPoint(double[])
-
query
public QuadTreeKD0.QIterator<T> query(double[] min, double[] max)
Query the tree, returning all points in the axis-aligned rectangle between 'min' and 'max'.
-
query1nn
public Index.PointEntryKnn<T> query1nn(double[] center)
Description copied from interface:PointMapFinds the nearest neighbor. This uses Euclidean distance. Other distance types can only be specified directly on the index implementations.
-
queryKnn
public Index.PointIteratorKnn<T> queryKnn(double[] center, int k, PointDistance dist)
Description copied from interface:PointMultimapFinds the nearest neighbor. This uses Euclidean distance. Other distance types can only be specified directly on the index implementations.- Specified by:
queryKnnin interfacePointMultimap<T>- Parameters:
center- center pointk- number of neighborsdist- the point distance function to be used- Returns:
- Iterator over query result
- See Also:
PointMultimap.queryKnn(double[], int, PointDistance)
-
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()
-
iterator
public Index.PointIterator<T> iterator()
-
queryKnn
public Index.PointIteratorKnn<T> queryKnn(double[] center, int k)
Description copied from interface:PointMapFinds the nearest neighbor. This uses Euclidean distance. Other distance types can only be specified directly on the index implementations.
-
getNodeCount
public int getNodeCount()
- Specified by:
getNodeCountin interfaceIndex
-
-