Klasse DoubleHeapPriorityQueue

java.lang.Object
speiger.src.collections.doubles.queues.AbstractDoublePriorityQueue
speiger.src.collections.doubles.queues.DoubleHeapPriorityQueue
Alle implementierten Schnittstellen:
Iterable<Double>, DoubleIterable, DoublePriorityQueue

public class DoubleHeapPriorityQueue extends AbstractDoublePriorityQueue
A Simple Heap base Priority Queue implementation It is a ArrayBased Alternative to TreeSets that has less object allocations
  • Konstruktordetails

    • DoubleHeapPriorityQueue

      public DoubleHeapPriorityQueue()
      Default Constructor
    • DoubleHeapPriorityQueue

      public DoubleHeapPriorityQueue(DoubleComparator comp)
      Constructor using custom sorter
      Parameter:
      comp - Comparator to sort the Array. Can be null
    • DoubleHeapPriorityQueue

      public DoubleHeapPriorityQueue(int size)
      Constructor with a Min Capacity
      Parameter:
      size - the initial capacity of the backing array
      Löst aus:
      IllegalStateException - if the initial size is smaller 0
    • DoubleHeapPriorityQueue

      public DoubleHeapPriorityQueue(int size, DoubleComparator comp)
      Constructor with a Min Capacity and custom Sorter
      Parameter:
      size - the initial capacity of the backing array
      comp - Comparator to sort the Array. Can be null
      Löst aus:
      IllegalStateException - if the initial size is smaller 0
    • DoubleHeapPriorityQueue

      public DoubleHeapPriorityQueue(double[] array)
      Constructor using a initial array
      Parameter:
      array - the Array that should be used
    • DoubleHeapPriorityQueue

      public DoubleHeapPriorityQueue(double[] array, int size)
      Constructor using a initial array
      Parameter:
      array - the Array that should be used
      size - the amount of elements found within the array
      Löst aus:
      NegativeArraySizeException - if size is smaller then 0
    • DoubleHeapPriorityQueue

      public DoubleHeapPriorityQueue(double[] array, DoubleComparator comp)
      Constructor using a initial array and a custom sorter
      Parameter:
      array - the Array that should be used
      comp - Comparator to sort the Array. Can be null
    • DoubleHeapPriorityQueue

      public DoubleHeapPriorityQueue(double[] array, int size, DoubleComparator comp)
      Constructor using a initial array and a custom sorter
      Parameter:
      array - the Array that should be used
      size - the amount of elements found within the array
      comp - Comparator to sort the Array. Can be null
      Löst aus:
      NegativeArraySizeException - if size is smaller then 0
    • DoubleHeapPriorityQueue

      public DoubleHeapPriorityQueue(DoubleCollection c)
      Constructor using a Collection
      Parameter:
      c - the Collection that should be used
    • DoubleHeapPriorityQueue

      public DoubleHeapPriorityQueue(DoubleCollection c, DoubleComparator comp)
      Constructor using a Collection and a custom sorter
      Parameter:
      c - the Collection that should be used
      comp - Comparator to sort the Array. Can be null
  • Methodendetails

    • wrap

      public static DoubleHeapPriorityQueue wrap(double[] array)
      Wrapping method to help serialization
      Parameter:
      array - the array that should be used
      Gibt zurück:
      a HeapPriorityQueue containing the original input array
    • wrap

      public static DoubleHeapPriorityQueue wrap(double[] array, int size)
      Wrapping method to help serialization
      Parameter:
      array - the array that should be used
      size - the amount of elements within the array
      Gibt zurück:
      a HeapPriorityQueue containing the original input array
    • wrap

      public static DoubleHeapPriorityQueue wrap(double[] array, DoubleComparator comp)
      Wrapping method to help serialization, using a custom sorter
      Parameter:
      array - the array that should be used
      comp - Comparator to sort the Array. Can be null
      Gibt zurück:
      a HeapPriorityQueue containing the original input array
    • wrap

      public static DoubleHeapPriorityQueue wrap(double[] array, int size, DoubleComparator comp)
      Wrapping method to help serialization, using a custom sorter
      Parameter:
      array - the array that should be used
      size - the amount of elements within the array
      comp - Comparator to sort the Array. Can be null
      Gibt zurück:
      a HeapPriorityQueue containing the original input array
    • size

      public int size()
      Gibt zurück:
      the amount of elements that are stored in the PriorityQueue
    • clear

      public void clear()
      Beschreibung aus Schnittstelle kopiert: DoublePriorityQueue
      clears all elements within the PriorityQueue, this does not resize the backing arrays
    • iterator

      public DoubleIterator iterator()
      Beschreibung aus Schnittstelle kopiert: DoubleIterable
      Returns an iterator over elements of type T.
      Gibt zurück:
      an Iterator.
    • enqueue

      public void enqueue(double e)
      Beschreibung aus Schnittstelle kopiert: DoublePriorityQueue
      Method to insert a element into the PriorityQueue
      Parameter:
      e - the element that should be inserted
    • dequeue

      public double dequeue()
      Beschreibung aus Schnittstelle kopiert: DoublePriorityQueue
      Method to extract a element from the PriorityQueue
      Gibt zurück:
      a element from the Queue
    • peek

      public double peek(int index)
      Beschreibung aus Schnittstelle kopiert: DoublePriorityQueue
      Peeking function to see whats inside the queue.
      Parameter:
      index - of the element that is requested to be viewed.
      Gibt zurück:
      the element that is requested
    • contains

      public boolean contains(double e)
      Beschreibung aus Schnittstelle kopiert: DoublePriorityQueue
      Method to find out if a element is part of the queue
      Parameter:
      e - the element that is searched for
      Gibt zurück:
      true if the element is in the queue
    • removeFirst

      public boolean removeFirst(double e)
      Beschreibung aus Schnittstelle kopiert: DoublePriorityQueue
      Removes the first found element in the queue
      Parameter:
      e - the element that should be removed
      Gibt zurück:
      if a searched element was removed
    • removeLast

      public boolean removeLast(double e)
      Beschreibung aus Schnittstelle kopiert: DoublePriorityQueue
      Removes the last found element in the queue
      Parameter:
      e - the element that should be removed
      Gibt zurück:
      if a searched element was removed
    • forEach

      public void forEach(DoubleConsumer action)
      Beschreibung aus Schnittstelle kopiert: DoubleIterable
      A Type Specific foreach function that reduces (un)boxing
      Parameter:
      action - The action to be performed for each element
      Siehe auch:
    • forEachIndexed

      public void forEachIndexed(IntDoubleConsumer action)
      Beschreibung aus Schnittstelle kopiert: DoubleIterable
      A Indexed forEach implementation that allows you to keep track of how many elements were already iterated over.
      Parameter:
      action - The action to be performed for each element
    • forEach

      public <E> void forEach(E input, ObjectDoubleConsumer<E> action)
      Beschreibung aus Schnittstelle kopiert: DoubleIterable
      Helper function to reduce Lambda usage and allow for more method references, since these are faster/cleaner.
      Typparameter:
      E - the generic type of the Object
      Parameter:
      input - the object that should be included
      action - The action to be performed for each element
    • matchesAny

      public boolean matchesAny(DoublePredicate filter)
      Beschreibung aus Schnittstelle kopiert: DoubleIterable
      Helper function to reduce stream usage that allows to filter for any matches.
      Parameter:
      filter - that should be applied
      Gibt zurück:
      true if any matches were found
    • matchesNone

      public boolean matchesNone(DoublePredicate filter)
      Beschreibung aus Schnittstelle kopiert: DoubleIterable
      Helper function to reduce stream usage that allows to filter for no matches.
      Parameter:
      filter - that should be applied
      Gibt zurück:
      true if no matches were found
    • matchesAll

      public boolean matchesAll(DoublePredicate filter)
      Beschreibung aus Schnittstelle kopiert: DoubleIterable
      Helper function to reduce stream usage that allows to filter for all matches.
      Parameter:
      filter - that should be applied
      Gibt zurück:
      true if all matches.
    • reduce

      public double reduce(double identity, DoubleDoubleUnaryOperator operator)
      Beschreibung aus Schnittstelle kopiert: DoubleIterable
      Performs a reduction on the elements of this Iterable
      Parameter:
      identity - the start value
      operator - the operation that should be applied
      Gibt zurück:
      the reduction result, returns identity if nothing was found
    • reduce

      public double reduce(DoubleDoubleUnaryOperator operator)
      Beschreibung aus Schnittstelle kopiert: DoubleIterable
      Performs a reduction on the elements of this Iterable
      Parameter:
      operator - the operation that should be applied
      Gibt zurück:
      the reduction result, returns null value if nothing was found
    • findFirst

      public double findFirst(DoublePredicate filter)
      Beschreibung aus Schnittstelle kopiert: DoubleIterable
      Helper function to reduce stream usage that allows to filter for the first match.
      Parameter:
      filter - that should be applied
      Gibt zurück:
      the found value or the null equivalent variant.
    • count

      public int count(DoublePredicate filter)
      Beschreibung aus Schnittstelle kopiert: DoubleIterable
      Helper function to reduce stream usage that allows to count the valid elements.
      Parameter:
      filter - that should be applied
      Gibt zurück:
      the amount of Valid Elements
    • onChanged

      public void onChanged()
      Beschreibung aus Schnittstelle kopiert: DoublePriorityQueue
      Allows to notify the Queue to be revalidate its data
    • copy

      public DoubleHeapPriorityQueue copy()
      Beschreibung aus Schnittstelle kopiert: DoublePriorityQueue
      A Function that does a shallow clone of the PriorityQueue itself. This function is more optimized then a copy constructor since the PriorityQueue does not have to be unsorted/resorted. It can be compared to Cloneable but with less exception risk
      Gibt zurück:
      a Shallow Copy of the PriorityQueue
    • comparator

      public DoubleComparator comparator()
      Gibt zurück:
      the sorter of the Queue, can be null
    • toDoubleArray

      public double[] toDoubleArray(double[] input)
      Beschreibung aus Schnittstelle kopiert: DoublePriorityQueue
      A method to drop the contents of the Queue without clearing the queue
      Parameter:
      input - where the elements should be inserted to. If it does not fit then it creates a new appropiatly created array
      Gibt zurück:
      the contents of the queue into a seperate array.