Class NearestNeighbourSearch.MyHeap

  • Enclosing class:
    NearestNeighbourSearch

    protected class NearestNeighbourSearch.MyHeap
    extends Object
    A class for a heap to store the nearest k neighbours to an instance. The heap also takes care of cases where multiple neighbours are the same distance away. i.e. the minimum size of the heap is k.
    Version:
    $Revision: 8034 $
    Author:
    Ashraf M. Kibriya (amk14[at-the-rate]cs[dot]waikato[dot]ac[dot]nz)
    • Constructor Detail

      • MyHeap

        public MyHeap​(int maxSize)
        constructor.
        Parameters:
        maxSize - the maximum size of the heap
    • Method Detail

      • size

        public int size()
        returns the size of the heap.
        Returns:
        the size
      • put

        public void put​(int i,
                        double d)
                 throws Exception
        adds the value to the heap.
        Parameters:
        i - the index
        d - the distance
        Throws:
        Exception - if the heap gets too large
      • putBySubstitute

        public void putBySubstitute​(int i,
                                    double d)
                             throws Exception
        Puts an element by substituting it in place of the top most element.
        Parameters:
        i - the index
        d - the distance
        Throws:
        Exception - if distance is smaller than that of the head element
      • noOfKthNearest

        public int noOfKthNearest()
        returns the number of k nearest.
        Returns:
        the number of k nearest
        See Also:
        m_KthNearestSize
      • putKthNearest

        public void putKthNearest​(int i,
                                  double d)
        Stores kth nearest elements (if there are more than one).
        Parameters:
        i - the index
        d - the distance
      • upheap

        protected void upheap()
        performs upheap operation for the heap to maintian its properties.
      • downheap

        protected void downheap()
        performs downheap operation for the heap to maintian its properties.
      • totalSize

        public int totalSize()
        returns the total size.
        Returns:
        the total size