public class DoubleRadixHeap extends Object
Note that this implementation uses the fact that the IEEE floating-point standard has the property that for any valid floating-point numbers a and b, a<=b if and only if bits(a)<= bits(b), where bits(x) denotes the re-interpretation of x as an unsigned integer (long in our case).
This implementation uses arrays in order to store the elements. Operations
insert and findMin are worst-case constant time. The cost of
operation deleteMin is amortized O(logC) assuming the radix-heap
contains keys in the range [0, C] or equivalently
[a,a+C]. Note, however, that C here depends on the distance of the
minimum and maximum value when they are translated into unsigned longs.
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.
| Constructor and Description |
|---|
DoubleRadixHeap(double minKey,
double maxKey)
Constructs a new heap which can store values between a minimum and a
maximum key value (inclusive).
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clear all the elements of this heap.
|
Comparator<? super K> |
comparator()
Always returns
null since this heap uses the
natural ordering of its keys. |
K |
deleteMin()
Delete and return an element with the minimum key.
|
K |
findMin()
Find an element with the minimum key.
|
void |
insert(K key)
Insert a key into the heap.
|
boolean |
isEmpty()
Returns
true if this heap is empty. |
long |
size()
Returns the number of elements in this heap.
|
public DoubleRadixHeap(double minKey,
double maxKey)
deleteMin requires amortized O(logC) time.minKey - the non-negative minimum key that this heap supports
(inclusive)maxKey - the maximum key that this heap supports (inclusive)IllegalArgumentException - if the minimum key is negativeIllegalArgumentException - if the maximum key is less than the minimum keypublic K findMin()
public void insert(K key)
insert in interface Heap<K>key - the key to insertIllegalArgumentException - if the key is nullIllegalArgumentException - if the key is less than the minimum allowed keyIllegalArgumentException - if the key is more than the maximum allowed keyIllegalArgumentException - if the key is less than the last deleted key (or the minimum
key allowed if no key has been deleted)public K deleteMin()
public boolean isEmpty()
true if this heap is empty.public long size()
public void clear()
public Comparator<? super K> comparator()
null since this heap uses the
natural ordering of its keys.comparator in interface Heap<K>null since this heap uses the natural ordering of its
keysCopyright © 2018. All rights reserved.