Class LseMinHeap


  • public class LseMinHeap
    extends java.lang.Object

    A class that encapsules a min-heap data structure. The minimum value of a set of numbers is guaranteed always to be at the root of the heap.

    Version:
    0.1 November 7, 2006
    Author:
    David Eberly
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  LseMinHeap.Record
      Each heap record stores a numeric value, the index of the record within the records array, and a generator which acts as an identifier for the application to use to store information about how the numeric value was generated in the application.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) LseMinHeap.Record[] m_akRecords
      The record storage for the heap, allocated in one large chunk.
      (package private) int m_iQuantity
      The number of active records in the heap.
    • Constructor Summary

      Constructors 
      Constructor Description
      LseMinHeap​(int iMaxQuantity)
      Create a new min-heap data structure.
    • Field Detail

      • m_iQuantity

        int m_iQuantity
        The number of active records in the heap.
      • m_akRecords

        LseMinHeap.Record[] m_akRecords
        The record storage for the heap, allocated in one large chunk.
    • Constructor Detail

      • LseMinHeap

        public LseMinHeap​(int iMaxQuantity)
        Create a new min-heap data structure.
        Parameters:
        iMaxQuantity - The maximum number of heap records. This number depends on the application's needs.
    • Method Detail

      • getQuantity

        public final int getQuantity()
        Get the current number of active heap records.
        Returns:
        The current number of active heap records.
      • getRecord

        public final LseMinHeap.Record getRecord​(int i)
        Get a record from the heap records.
        Parameters:
        i - The index of the desired record.
        Returns:
        The desired record.
      • insert

        public final LseMinHeap.Record insert​(int iGenerator,
                                              float fValue)
        Insert a numeric value into the min-heap data structure.
        Parameters:
        iGenerator - The application-specific identifier that is associated with the numeric value managed by the heap record.
        fValue - The numeric value managed by the heap record.
        Returns:
        The heap record that manages the numeric value.
      • remove

        public final LseMinHeap.Record remove()
        Remove the root of the heap. The root contains the minimum value of all heap elements.
        Returns:
        The record that corresponded to the root of the heap.
      • update

        public final void update​(LseMinHeap.Record kRecord,
                                 float fValue)
        The value of a heap record must be modified through this function call. The side effect is that the heap must be updated accordingly to accommodate the new value.
        Parameters:
        kRecord - The record to be updated.
        fValue - The record's new numeric value.