|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.savarese.spatial.KDTree<Coord,P,V>
public class KDTree<Coord extends java.lang.Comparable<? super Coord>,P extends Point<Coord>,V>
A k-d tree divides a k-dimensional space relative to the points it contains by storing them in a binary tree, discriminating by a different dimension at each level of the tree. It allows efficient point data retrieval (O(lg(n))) and range searching.
KDTree conforms to the java.util.Map interface except that Iterator.remove is not supported by the returned views.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface java.util.Map |
---|
java.util.Map.Entry<K,V> |
Constructor Summary | |
---|---|
KDTree()
Creates a two-dimensional KDTree. |
|
KDTree(int dimensions)
Creates a KDTree of the specified number of dimensions. |
Method Summary | |
---|---|
void |
clear()
Removes all elements from the container, leaving it empty. |
boolean |
containsKey(java.lang.Object key)
Returns true if the container contains a mapping for the specified key. |
boolean |
containsValue(java.lang.Object value)
Returns true if the container contains a mapping with the specified value. |
java.util.Set<java.util.Map.Entry<P,V>> |
entrySet()
Returns a Set view of the point to value mappings in the KDTree. |
boolean |
equals(java.lang.Object o)
Returns true if the object contains the same mappings, false if not. |
V |
get(java.lang.Object point)
Retrieves the value at the given location. |
int |
hashCode()
Returns the hash code value for this map. |
boolean |
isEmpty()
Returns true if the container has no elements, false if it contains one or more elements. |
java.util.Iterator<java.util.Map.Entry<P,V>> |
iterator(P lower,
P upper)
Returns an iterator for mappings that are contained in the rectangle defined by the given lower left-hand and upper right-hand corners. |
java.util.Set<P> |
keySet()
Returns a Set view of the point keys for the mappings in the KDTree. |
void |
optimize()
Optimizes the performance of future search operations by balancing the KDTree. |
V |
put(P point,
V value)
Inserts a point value pair into the tree, preserving the spatial ordering. |
void |
putAll(java.util.Map<? extends P,? extends V> map)
Copies all of the point-value mappings from the given Map into the KDTree. |
V |
remove(java.lang.Object key)
Removes the point-value mapping corresponding to the given point key. |
int |
size()
Returns the number of point-value mappings in the KDTree. |
java.util.Collection<V> |
values()
Returns a Collection view of the values contained in the KDTree. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public KDTree()
public KDTree(int dimensions)
dimensions
- The number of dimensions. Must be greater than 0.Method Detail |
---|
public void clear()
clear
in interface java.util.Map<P extends Point<Coord>,V>
public boolean containsKey(java.lang.Object key) throws java.lang.ClassCastException
containsKey
in interface java.util.Map<P extends Point<Coord>,V>
key
- The point key to search for.
java.lang.ClassCastException
- if the key is not an instance of P.public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map<P extends Point<Coord>,V>
value
- The value to search for.
public java.util.Set<java.util.Map.Entry<P,V>> entrySet()
Iterator.remove
is not supported.
entrySet
in interface java.util.Map<P extends Point<Coord>,V>
public boolean equals(java.lang.Object o) throws java.lang.ClassCastException
equals
in interface java.util.Map<P extends Point<Coord>,V>
equals
in class java.lang.Object
o
- The object to test for equality.
java.lang.ClassCastException
public V get(java.lang.Object point) throws java.lang.ClassCastException
get
in interface java.util.Map<P extends Point<Coord>,V>
point
- The location from which to retrieve the value.
java.lang.ClassCastException
- If the given point is not of the
expected type.public int hashCode()
hashCode
in interface java.util.Map<P extends Point<Coord>,V>
hashCode
in class java.lang.Object
public boolean isEmpty()
isEmpty
in interface java.util.Map<P extends Point<Coord>,V>
public java.util.Set<P> keySet()
Iterator.remove
is not supported.
keySet
in interface java.util.Map<P extends Point<Coord>,V>
public V put(P point, V value)
put
in interface java.util.Map<P extends Point<Coord>,V>
point
- The point serving as a key.value
- The value to insert at the point.
public void putAll(java.util.Map<? extends P,? extends V> map)
putAll
in interface java.util.Map<P extends Point<Coord>,V>
map
- The Map from which to copy the mappings.public V remove(java.lang.Object key) throws java.lang.ClassCastException
remove
in interface java.util.Map<P extends Point<Coord>,V>
key
- The point key of the mapping to remove.
java.lang.ClassCastException
- If the key is not an instance of P.public int size()
size
in interface java.util.Map<P extends Point<Coord>,V>
public java.util.Collection<V> values()
values
in interface java.util.Map<P extends Point<Coord>,V>
public java.util.Iterator<java.util.Map.Entry<P,V>> iterator(P lower, P upper)
RangeSearchTree
iterator
in interface RangeSearchTree<Coord extends java.lang.Comparable<? super Coord>,P extends Point<Coord>,V>
lower
- The lower left-hand corner of the bounding
rectangle. A null value can be used to specify the region is
unbounded in that direction.upper
- The upper right-hand corner of the bounding
rectangle. A null value can be used to specify the region is
unbounded in that direction.
public void optimize()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |