Package smile.util
Class PairingHeap<E extends Comparable<E>>
java.lang.Object
smile.util.PairingHeap<E>
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,Queue<E>
A pairing heap is a type of heap data structure with relatively simple
implementation and excellent practical amortized performance. Pairing
heaps are heap-ordered multiway tree structures, and can be considered
simplified Fibonacci heaps. They are considered a robust choice for
implementing such algorithms as Prim's MST algorithm.
-
Nested Class Summary
Modifier and TypeClassDescriptionclass
A multiway tree node in the pairing heap. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
addAll
(Collection<? extends E> c) Adds a new element to the pairing heap.void
clear()
boolean
boolean
containsAll
(Collection<?> c) element()
boolean
isEmpty()
iterator()
boolean
peek()
poll()
void
rebuild()
Rebuilds the pairing heap.remove()
boolean
boolean
removeAll
(Collection<?> c) boolean
retainAll
(Collection<?> c) int
size()
Object[]
toArray()
<T> T[]
toArray
(T[] a) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
Constructor Details
-
PairingHeap
public PairingHeap()
-
-
Method Details
-
size
public int size()- Specified by:
size
in interfaceCollection<E extends Comparable<E>>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<E extends Comparable<E>>
-
addNode
Adds a new element to the pairing heap.- Parameters:
value
- a new element.- Returns:
- a Node corresponding to the newly added element.
-
rebuild
public void rebuild()Rebuilds the pairing heap. Assumes that all elements inside the pairing heap are out of order due to side-channel updates. -
add
- Specified by:
add
in interfaceCollection<E extends Comparable<E>>
- Specified by:
add
in interfaceQueue<E extends Comparable<E>>
-
offer
- Specified by:
offer
in interfaceQueue<E extends Comparable<E>>
-
peek
- Specified by:
peek
in interfaceQueue<E extends Comparable<E>>
-
element
- Specified by:
element
in interfaceQueue<E extends Comparable<E>>
-
poll
- Specified by:
poll
in interfaceQueue<E extends Comparable<E>>
-
remove
- Specified by:
remove
in interfaceQueue<E extends Comparable<E>>
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<E extends Comparable<E>>
-
addAll
- Specified by:
addAll
in interfaceCollection<E extends Comparable<E>>
-
contains
- Specified by:
contains
in interfaceCollection<E extends Comparable<E>>
-
containsAll
- Specified by:
containsAll
in interfaceCollection<E extends Comparable<E>>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<E extends Comparable<E>>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<E extends Comparable<E>>
-
remove
- Specified by:
remove
in interfaceCollection<E extends Comparable<E>>
-
toArray
- Specified by:
toArray
in interfaceCollection<E extends Comparable<E>>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArray
in interfaceCollection<E extends Comparable<E>>
-
iterator
- Specified by:
iterator
in interfaceCollection<E extends Comparable<E>>
- Specified by:
iterator
in interfaceIterable<E extends Comparable<E>>
-