Documentation of 'jvx.util.PuPriorityQueue' Java class
PuPriorityQueue ("JavaView Reference Manual")
"JavaView? v5.03.003"
jvx.util

Class PuPriorityQueue

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, PsUpdateIf


    public final class PuPriorityQueue
    extends PsObject
    Integer heap with double keys (resp. weights) based on following special property: The ints given to the heap must be the numbers from 0 to capacity-1 and each int can be in the heap just once. As a result methods like isElement() run in O(1) time.

    We call the integers in the heap elements.

    Heap is used e.g. to compute a minimum spanning tree on the vertices resp. faces of a geometry with weight assigned to each edge (cp. Prim's algorithm for minimal spanning trees).

    See Also:
    Serialized Form
    Author:
    Klaus Hildebrandt
    Version:
    01.03.07, 2.01 revised (mn) Added field m_capacity.
    09.12.06, 2.00 revised (kp) Moved to jvx.util from jvx.geom.
    07.08.06, 1.30 revised (fk) New methods toString and #extractElement(int) extractElement}.
    20.01.05, 1.20 revised (ep) New methods increaseKey and changeKey.
    12.02.04, 1.10 revised (kh) Renamed data[][] to m_positions and m_elements.
    00.01.03, 1.00 created (kh)
    • Constructor Detail

      • PuPriorityQueue

        public PuPriorityQueue(int capacity)
        Create an empty priority queue with a given capacity.
      • PuPriorityQueue

        public PuPriorityQueue(double[] key)
        Create a priority queue that has the elements 0...key.length and the given keys.
      • PuPriorityQueue

        public PuPriorityQueue(int capacity,
                               double key)
        Create a priority queue containing the elements 0,1,2,...capacity-1. All elements get the same (given) key.
    • Method Detail

      • getCapacity

        public int getCapacity()
        Maximal heap size for this heap.
      • getElements

        public int[] getElements()
        Get the array, where the heap stores the elements.
      • getElement

        public int getElement(int position)
        Method returns the index of the element at the specified position.
      • getPositions

        public int[] getPositions()
        Get the array, where the heap stores the positions of the elements.
      • getPosition

        public int getPosition(int element)
        Method returns the position of the specified element in the heap. If the element is not in the heap, -1 is returned.
      • getKeys

        public double[] getKeys()
        Get the array containing the key of each element.
      • getKey

        public double getKey(int element)
        Method returns the key of the specified element. Method returns the key even if the element has already been extracted from the heap.
      • decreaseKey

        public boolean decreaseKey(int element,
                                   double key)
        Decrease the key assigned to an element and reorder the heap. If the key is bigger than the actual key of the element nothing is done.
        Returns:
        false if element does not exist or its key is smaller than parameter key
      • increaseKey

        public boolean increaseKey(int element,
                                   double key)
        Increases the key assigned to an element and reorder the heap. If the key is smaller than the actual key of the element, nothing is done.
        Returns:
        false if element does not exist or its key is greater than parameter key
      • changeKey

        public boolean changeKey(int element,
                                 double key)
        Changes the key assigned to an element and reorder the heap.
        Returns:
        false if element does not exist
        Author:
        Eike Preuss
        Version:
        20.01.05, 1.00 created (ep)
      • getKeyOfMin

        public double getKeyOfMin()
        Get key of minimal element.
      • extractMin

        public int extractMin()
        Extract the element with the smallest key of the heap. To get the key of the element use getKey(int).
      • extractElement

        public double extractElement(int element)
        Remove a specific element from the heap and return its key. If the specified element index is out of range, NaN is returned.
        Parameters:
        element - index of the element to extract.
        Returns:
        Key of the extracted element, or NaN if argument is no queue element.
        Author:
        Felix Kaelberer
        Version:
        07.08.2006, 1.00 created (fk)
      • getHeapSize

        public int getHeapSize()
        Get the number of Elements in the heap.
      • isEmpty

        public boolean isEmpty()
        Returns true, if there is no element in the heap.
      • isElement

        public boolean isElement(int element)
        Check if element i is in the heap.
      • enqueue

        public boolean enqueue(int element,
                               double key)
        Add element to heap. If element is already in the heap nothing is done and false is returned.
      • enqueueOrDecrease

        public boolean enqueueOrDecrease(int element,
                                         double key)
        Add element to heap. If the element is already in the heap and the given key is smaller than the actual key, decrease its key.
      • emptyHeap

        public void emptyHeap()
        Remove all elements from heap.
      • toString

        public java.lang.String toString()
        Create a multi-line string representation with detailed information about instance variables.
        Overrides:
        toString in class PsObject
        Author:
        Felix Kaelberer
        Version:
        07.08.2006, 1.00 created (fk)
"JavaView? v5.03.003"

"

The software JavaView? is copyright protected. All Rights Reserved.
"

Ads help maintain this website.