Class LongArrayHeap

java.lang.Object
java.util.AbstractCollection<Long>
org.jhotdraw8.collection.primitive.LongArrayHeap
All Implemented Interfaces:
Serializable, Cloneable, Iterable<Long>, Collection<Long>, Queue<Long>, LongQueue

public class LongArrayHeap extends AbstractCollection<Long> implements LongQueue, Serializable, Cloneable
An optimized array-based binary heap with long keys.

This is a highly optimized implementation which uses

  1. the Wegener bottom-up heuristic and
  2. sentinel values
The implementation uses an array in order to store the elements, providing amortized O(log(n)) time for the addAsLong(long) and removeAsLong() operations. Operation findMin, is a worst-case O(1) operation. All bounds are worst-case if the user initializes the heap with a capacity larger or equal to the total number of elements that are going to be inserted into the heap.

See the following papers for details about the optimizations:

  • Ingo Wegener. BOTTOM-UP-HEAPSORT, a new variant of HEAPSORT beating, on an average, QUICKSORT (if n is not very small). Theoretical Computer Science, 118(1), 81--98, 1993.
  • Peter Sanders. Fast Priority Queues for Cached Memory. Algorithms Engineering and Experiments (ALENEX), 312--327, 1999.

Note that this implementation is not synchronized. If multiple threads access a heap concurrently, and at least one of the threads modifies the heap structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more elements or changing the key of some element.) This is typically accomplished by synchronizing on some object that naturally encapsulates the heap.

Author:
Dimitrios Michail
JHeaps Library
Copyright (c) 2014-2022 Dimitrios Michail. Apache License 2.0.
github.com
See Also: