V - the type of values maintained by this heappublic class BigIntegerRadixAddressableHeap<V> extends Object
BigInteger keys. The heap stores
BigInteger keys sorted according to the natural ordering of its keys. A radix heap is a monotone heap, especially
designed for algorithms (such as Dijkstra) which scan elements in order of
nondecreasing keys.
The implementation use 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 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.
AddressableHeap,
Serialized FormAddressableHeap.Handle<K,V>| Constructor and Description |
|---|
BigIntegerRadixAddressableHeap(BigInteger minKey,
BigInteger 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 the heap.
|
Comparator<? super K> |
comparator()
Always returns
null since this heap uses the
natural ordering of its keys. |
AddressableHeap.Handle<K,V> |
deleteMin()
Delete and return an element with the minimum key.
|
AddressableHeap.Handle<K,V> |
findMin()
Find an element with the minimum key.
|
AddressableHeap.Handle<K,V> |
insert(K key)
Insert a new element into the heap with a null value.
|
AddressableHeap.Handle<K,V> |
insert(K key,
V value)
Insert a new element into the heap.
|
boolean |
isEmpty()
Returns
true if this heap is empty. |
long |
size()
Returns the number of elements in the heap.
|
public BigIntegerRadixAddressableHeap(BigInteger minKey, BigInteger 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 AddressableHeap.Handle<K,V> findMin()
findMin in interface AddressableHeap<K,V>public AddressableHeap.Handle<K,V> insert(K key)
insert in interface AddressableHeap<K,V>key - the element's keyIllegalArgumentException - 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 AddressableHeap.Handle<K,V> insert(K key, V value)
insert in interface AddressableHeap<K,V>key - the element's keyvalue - the element's valueIllegalArgumentException - 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 AddressableHeap.Handle<K,V> deleteMin()
AddressableHeap.Handle.getKey()
and AddressableHeap.Handle.getValue() can be used.
The cost of this operation is amortized O(logC) assuming the heap
contains keys in the range [0, C] or equivalently [a, a+C].deleteMin in interface AddressableHeap<K,V>public boolean isEmpty()
true if this heap is empty.isEmpty in interface AddressableHeap<K,V>true if this heap is empty, false otherwisepublic long size()
size in interface AddressableHeap<K,V>public void clear()
AddressableHeap.Handle.decreaseKey(Object) and AddressableHeap.Handle.delete() is
undefined.clear in interface AddressableHeap<K,V>public Comparator<? super K> comparator()
null since this heap uses the
natural ordering of its keys.comparator in interface AddressableHeap<K,V>null since this heap uses the natural ordering of its
keysCopyright © 2018. All rights reserved.