Class FloatHeap


  • public final class FloatHeap
    extends java.lang.Object
    A bounded min heap that stores floats. The top element is the lowest value of the heap.

    A primitive priority queue that maintains a partial ordering of its elements such that the least element can always be found in constant time. Implementation is based on LongHeap

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private float[] heap  
      private int maxSize  
      private int size  
    • Constructor Summary

      Constructors 
      Constructor Description
      FloatHeap​(int maxSize)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()  
      private void downHeap​(int i)  
      float[] getHeap()  
      boolean offer​(float value)
      Inserts a value into this heap.
      float peek()
      Retrieves, but does not remove, the head of this heap.
      float poll()
      Removes and returns the head of the heap
      private void push​(float element)  
      int size()
      Returns the number of elements in this heap.
      private float updateTop​(float value)  
      private void upHeap​(int origPos)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • maxSize

        private final int maxSize
      • heap

        private final float[] heap
      • size

        private int size
    • Constructor Detail

      • FloatHeap

        public FloatHeap​(int maxSize)
    • Method Detail

      • offer

        public boolean offer​(float value)
        Inserts a value into this heap.

        If the number of values would exceed the heap's maxSize, the least value is discarded

        Parameters:
        value - the value to add
        Returns:
        whether the value was added (unless the heap is full, or the new value is less than the top value)
      • getHeap

        public float[] getHeap()
      • poll

        public float poll()
        Removes and returns the head of the heap
        Returns:
        the head of the heap, the smallest value
        Throws:
        java.lang.IllegalStateException - if the heap is empty
      • peek

        public float peek()
        Retrieves, but does not remove, the head of this heap.
        Returns:
        the head of the heap, the smallest value
      • size

        public int size()
        Returns the number of elements in this heap.
        Returns:
        the number of elements in this heap
      • clear

        public void clear()
      • push

        private void push​(float element)
      • updateTop

        private float updateTop​(float value)
      • downHeap

        private void downHeap​(int i)
      • upHeap

        private void upHeap​(int origPos)