Class DoubleArrayIndirectPriorityQueue
- All Implemented Interfaces:
DoubleIndirectPriorityQueue,it.unimi.dsi.fastutil.IndirectPriorityQueue<Double>
Instances of this class use as reference list a reference array,
which must be provided to each constructor, and represent a priority queue
using a backing array of integer indices—all operations are performed
directly on the array. The array is enlarged as needed, but it is never
shrunk. Use the trim() method to reduce its size, if necessary.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int[]The backing array.protected it.unimi.dsi.fastutil.doubles.DoubleComparatorThe type-specific comparator used in this queue.protected intThe first index, cached, iffirstIndexValidis true.protected booleanWhetherfirstIndexcontains a valid value.protected double[]The reference array.protected intThe number of elements in this queue. -
Constructor Summary
ConstructorsConstructorDescriptionDoubleArrayIndirectPriorityQueue(double[] refArray) Creates a new empty queue with capacity equal to the length of the reference array and using the natural order.DoubleArrayIndirectPriorityQueue(double[] refArray, int capacity) Creates a new empty queue with given capacity and using the natural order.DoubleArrayIndirectPriorityQueue(double[] refArray, int[] a) Wraps a given array in a queue using the natural order.DoubleArrayIndirectPriorityQueue(double[] refArray, int[] a, int size) Wraps a given array in a queue using the natural order.DoubleArrayIndirectPriorityQueue(double[] refArray, int[] a, int size, it.unimi.dsi.fastutil.doubles.DoubleComparator c) Wraps a given array in a queue using a given comparator.DoubleArrayIndirectPriorityQueue(double[] refArray, int[] a, it.unimi.dsi.fastutil.doubles.DoubleComparator c) Wraps a given array in a queue using a given comparator.DoubleArrayIndirectPriorityQueue(double[] refArray, int capacity, it.unimi.dsi.fastutil.doubles.DoubleComparator c) Creates a new empty queue without elements with a given capacity and comparator.DoubleArrayIndirectPriorityQueue(double[] refArray, it.unimi.dsi.fastutil.doubles.DoubleComparator c) Creates a new empty queue with capacity equal to the length of the reference array and a given comparator. -
Method Summary
Modifier and TypeMethodDescriptionvoidSignals the queue that all elements have changed.voidchanged()voidchanged(int index) voidclear()it.unimi.dsi.fastutil.doubles.DoubleComparatorReturns the type-specific comparator associated with this queue.intdequeue()voidenqueue(int x) protected voidensureElement(int index) Ensures that the given index is a firstIndexValid reference.protected final voidintfirst()intfront(int[] a) Writes in the provided array the front of the queue, that is, the set of indices whose elements have the same priority as the top.intlast()booleanremove(int index) intsize()toString()voidtrim()Trims the backing array so that it has exactlysize()elements.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface it.unimi.dsi.fastutil.IndirectPriorityQueue
contains, isEmpty
-
Field Details
-
refArray
protected double[] refArrayThe reference array. -
array
protected int[] arrayThe backing array. -
size
protected int sizeThe number of elements in this queue. -
c
protected it.unimi.dsi.fastutil.doubles.DoubleComparator cThe type-specific comparator used in this queue. -
firstIndex
protected int firstIndexThe first index, cached, iffirstIndexValidis true. -
firstIndexValid
protected boolean firstIndexValidWhetherfirstIndexcontains a valid value.
-
-
Constructor Details
-
DoubleArrayIndirectPriorityQueue
public DoubleArrayIndirectPriorityQueue(double[] refArray, int capacity, it.unimi.dsi.fastutil.doubles.DoubleComparator c) Creates a new empty queue without elements with a given capacity and comparator.- Parameters:
refArray- the reference array.capacity- the initial capacity of this queue.c- the comparator used in this queue, ornullfor the natural order.
-
DoubleArrayIndirectPriorityQueue
public DoubleArrayIndirectPriorityQueue(double[] refArray, int capacity) Creates a new empty queue with given capacity and using the natural order.- Parameters:
refArray- the reference array.capacity- the initial capacity of this queue.
-
DoubleArrayIndirectPriorityQueue
public DoubleArrayIndirectPriorityQueue(double[] refArray, it.unimi.dsi.fastutil.doubles.DoubleComparator c) Creates a new empty queue with capacity equal to the length of the reference array and a given comparator.- Parameters:
refArray- the reference array.c- the comparator used in this queue, ornullfor the natural order.
-
DoubleArrayIndirectPriorityQueue
public DoubleArrayIndirectPriorityQueue(double[] refArray) Creates a new empty queue with capacity equal to the length of the reference array and using the natural order.- Parameters:
refArray- the reference array.
-
DoubleArrayIndirectPriorityQueue
public DoubleArrayIndirectPriorityQueue(double[] refArray, int[] a, int size, it.unimi.dsi.fastutil.doubles.DoubleComparator c) Wraps a given array in a queue using a given comparator.The queue returned by this method will be backed by the given array.
- Parameters:
refArray- the reference array.a- an array of indices intorefArray.size- the number of elements to be included in the queue.c- the comparator used in this queue, ornullfor the natural order.
-
DoubleArrayIndirectPriorityQueue
public DoubleArrayIndirectPriorityQueue(double[] refArray, int[] a, it.unimi.dsi.fastutil.doubles.DoubleComparator c) Wraps a given array in a queue using a given comparator.The queue returned by this method will be backed by the given array.
- Parameters:
refArray- the reference array.a- an array of indices intorefArray.c- the comparator used in this queue, ornullfor the natural order.
-
DoubleArrayIndirectPriorityQueue
public DoubleArrayIndirectPriorityQueue(double[] refArray, int[] a, int size) Wraps a given array in a queue using the natural order.The queue returned by this method will be backed by the given array.
- Parameters:
refArray- the reference array.a- an array of indices intorefArray.size- the number of elements to be included in the queue.
-
DoubleArrayIndirectPriorityQueue
public DoubleArrayIndirectPriorityQueue(double[] refArray, int[] a) Wraps a given array in a queue using the natural order.The queue returned by this method will be backed by the given array.
- Parameters:
refArray- the reference array.a- an array of indices intorefArray.
-
-
Method Details
-
ensureNonEmpty
protected final void ensureNonEmpty() -
ensureElement
protected void ensureElement(int index) Ensures that the given index is a firstIndexValid reference.- Parameters:
index- an index in the reference array.- Throws:
IndexOutOfBoundsException- if the given index is negative or larger than the reference array length.
-
enqueue
public void enqueue(int x) Note that for efficiency reasons this method will not throw an exception when
xis already in the queue. However, the queue state will become inconsistent and the following behaviour will not be predictable.- Specified by:
enqueuein interfaceit.unimi.dsi.fastutil.IndirectPriorityQueue<Double>
-
dequeue
public int dequeue()- Specified by:
dequeuein interfaceit.unimi.dsi.fastutil.IndirectPriorityQueue<Double>
-
first
public int first()- Specified by:
firstin interfaceit.unimi.dsi.fastutil.IndirectPriorityQueue<Double>
-
last
public int last()- Specified by:
lastin interfaceit.unimi.dsi.fastutil.IndirectPriorityQueue<Double>
-
changed
public void changed()- Specified by:
changedin interfaceit.unimi.dsi.fastutil.IndirectPriorityQueue<Double>
-
changed
public void changed(int index) Note that for efficiency reasons this method will not throw an exception when
indexis not in the queue.- Specified by:
changedin interfaceit.unimi.dsi.fastutil.IndirectPriorityQueue<Double>
-
allChanged
public void allChanged()Signals the queue that all elements have changed.- Specified by:
allChangedin interfaceit.unimi.dsi.fastutil.IndirectPriorityQueue<Double>
-
remove
public boolean remove(int index) - Specified by:
removein interfaceit.unimi.dsi.fastutil.IndirectPriorityQueue<Double>
-
front
public int front(int[] a) Writes in the provided array the front of the queue, that is, the set of indices whose elements have the same priority as the top.- Specified by:
frontin interfaceit.unimi.dsi.fastutil.IndirectPriorityQueue<Double>- Parameters:
a- an array whose initial part will be filled with the frnot (must be sized as least as the heap size).- Returns:
- the number of elements of the front.
-
size
public int size()- Specified by:
sizein interfaceit.unimi.dsi.fastutil.IndirectPriorityQueue<Double>
-
clear
public void clear()- Specified by:
clearin interfaceit.unimi.dsi.fastutil.IndirectPriorityQueue<Double>
-
trim
public void trim()Trims the backing array so that it has exactlysize()elements. -
comparator
public it.unimi.dsi.fastutil.doubles.DoubleComparator comparator()Description copied from interface:DoubleIndirectPriorityQueueReturns the type-specific comparator associated with this queue.- Specified by:
comparatorin interfaceDoubleIndirectPriorityQueue- Specified by:
comparatorin interfaceit.unimi.dsi.fastutil.IndirectPriorityQueue<Double>- Returns:
- the comparator associated with this queue.
- See Also:
-
toString
-