Class KDTree<T>

    • Method Detail

      • create

        public static <T> KDTree<T> create​(int dims)
      • insert

        public void insert​(double[] key,
                           T value)
        Insert a key-value pair.
        Specified by:
        insert in interface PointMap<T>
        Specified by:
        insert in interface PointMultimap<T>
        Parameters:
        key - the key
        value - the value
      • contains

        public boolean contains​(double[] key)
        Check whether a given key exists.
        Specified by:
        contains in interface PointMap<T>
        Parameters:
        key - the key to check
        Returns:
        true iff the key exists
      • queryExactPoint

        public KDIterator<T> queryExactPoint​(double[] point)
        Lookup an entry, using exact match.
        Specified by:
        queryExactPoint in interface PointMultimap<T>
        Parameters:
        point - the point
        Returns:
        an iterator over all entries at the given point
      • queryExact

        public T queryExact​(double[] key)
        Get the value associates with the key.
        Specified by:
        queryExact in interface PointMap<T>
        Parameters:
        key - the key to look up
        Returns:
        the value for the key or 'null' if the key was not found
      • remove

        public boolean remove​(double[] key,
                              T value)
        Remove all entries at the given point.
        Specified by:
        remove in interface PointMultimap<T>
        Parameters:
        key - the point
        value - only entries with this value are removed
        Returns:
        `true` iff an entry was found and removed
      • remove

        public T remove​(double[] key)
        Remove a key.
        Specified by:
        remove in interface PointMap<T>
        Parameters:
        key - key to remove
        Returns:
        the value associated with the key or 'null' if the key was not found
      • removeIf

        public boolean removeIf​(double[] key,
                                Predicate<Index.PointEntry<T>> pred)
        Description copied from interface: PointMultimap
        Remove *one* entry with the given condition.
        Specified by:
        removeIf in interface PointMultimap<T>
        Parameters:
        key - the point
        pred - 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.
        Specified by:
        update in interface PointMap<T>
        Parameters:
        oldKey - old key
        newKey - new key
        Returns:
        the value associated with the key or 'null' if the key was not found.
      • update

        public boolean update​(double[] oldKey,
                              double[] newKey,
                              T value)
        Reinsert the key.
        Specified by:
        update in interface PointMultimap<T>
        Parameters:
        oldKey - old key
        newKey - new key
        value - the value of the entry that should be updated
        Returns:
        `true` iff the entry was found and updated
      • contains

        public boolean contains​(double[] key,
                                T value)
        Description copied from interface: PointMultimap
        Lookup an entry, using exact match.
        Specified by:
        contains in interface PointMultimap<T>
        Parameters:
        key - the point
        value - the value
        Returns:
        `true` if an entry was found, otherwise `false`.
      • size

        public int size()
        Get the number of key-value pairs in the tree.
        Specified by:
        size in interface Index
        Returns:
        the size
      • clear

        public void clear()
        Removes all elements from the tree.
        Specified by:
        clear in interface Index
      • query

        public KDIterator<T> query​(double[] min,
                                   double[] max)
        Query the tree, returning all points in the axis-aligned rectangle between 'min' and 'max'.
        Specified by:
        query in interface PointMap<T>
        Specified by:
        query in interface PointMultimap<T>
        Parameters:
        min - lower left corner of query
        max - upper right corner of query
        Returns:
        all entries in the rectangle
      • toStringTree

        public String toStringTree()
        Returns a printable list of the tree.
        Specified by:
        toStringTree in interface Index
        Returns:
        the tree as String
      • getStats

        public KDTree.KDStats getStats()
        Specified by:
        getStats in interface Index
        Returns:
        Collect and return some index statistics. Note that indexes are not required to fill all fields. Also, individual indexes may use subclasses with additional fields.
      • getDims

        public int getDims()
        Specified by:
        getDims in interface Index
        Returns:
        the number of dimensions
      • query1nn

        public Index.PointEntryKnn<T> query1nn​(double[] center)
        Description copied from interface: PointMap
        Finds the nearest neighbor. This uses Euclidean distance. Other distance types can only be specified directly on the index implementations.
        Specified by:
        query1nn in interface PointMap<T>
        Specified by:
        query1nn in interface PointMultimap<T>
        Parameters:
        center - center point
        Returns:
        the nearest neighbor
      • queryKnn

        public Index.PointIteratorKnn<T> queryKnn​(double[] center,
                                                  int k)
        Description copied from interface: PointMap
        Finds the nearest neighbor. This uses Euclidean distance. Other distance types can only be specified directly on the index implementations.
        Specified by:
        queryKnn in interface PointMap<T>
        Specified by:
        queryKnn in interface PointMultimap<T>
        Parameters:
        center - center point
        k - number of neighbors
        Returns:
        list of nearest neighbors
      • queryKnn

        public Index.PointIteratorKnn<T> queryKnn​(double[] center,
                                                  int k,
                                                  PointDistance distFn)
        Description copied from interface: PointMultimap
        Finds the nearest neighbor. This uses Euclidean distance. Other distance types can only be specified directly on the index implementations.
        Specified by:
        queryKnn in interface PointMultimap<T>
        Parameters:
        center - center point
        k - number of neighbors
        distFn - the point distance function to be used
        Returns:
        list of nearest neighbors
      • getNodeCount

        public int getNodeCount()
        Specified by:
        getNodeCount in interface Index
      • getDepth

        public int getDepth()
        Specified by:
        getDepth in interface Index