Package org.jheaps.monotone
Class LongRadixHeap
- java.lang.Object
- 
- org.jheaps.monotone.LongRadixHeap
 
- 
- All Implemented Interfaces:
- Serializable,- Heap<Long>
 
 public class LongRadixHeap extends Object A radix heap for (signed) long keys. The heap stores long 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.This implementation uses arrays in order to store the elements. Operations insertandfindMinare worst-case constant time. The cost of operationdeleteMinis amortized O(logC) assuming the radix-heap contains keys in the range [0, C] or equivalently [a,a+C]. Long values are viewed as signed numbers.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
- See Also:
- Serialized Form
 
- 
- 
Constructor SummaryConstructors Constructor Description LongRadixHeap(long minKey, long maxKey)Constructs a new heap which can store values between a minimum and a maximum key value (inclusive).
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clear all the elements of this heap.Comparator<? super K>comparator()Always returnsnullsince this heap uses the natural ordering of its keys.KdeleteMin()Delete and return an element with the minimum key.KfindMin()Find an element with the minimum key.voidinsert(K key)Insert a key into the heap.booleanisEmpty()Returnstrueif this heap is empty.longsize()Returns the number of elements in this heap.
 
- 
- 
- 
Constructor Detail- 
LongRadixHeappublic LongRadixHeap(long minKey, long maxKey)Constructs a new heap which can store values between a minimum and a maximum key value (inclusive). It is important to use the smallest key range as the heap uses O(logC) where C=maxKey-minKey+1 buckets to store elements. Moreover, the operationdeleteMinrequires amortized O(logC) time.- Parameters:
- minKey- the non-negative minimum key that this heap supports (inclusive)
- maxKey- the maximum key that this heap supports (inclusive)
- Throws:
- IllegalArgumentException- if the minimum key is negative
- IllegalArgumentException- if the maximum key is less than the minimum key
 
 
- 
 - 
Method Detail- 
findMinpublic K findMin() Find an element with the minimum key.
 - 
insertpublic void insert(K key) Insert a key into the heap.- Specified by:
- insertin interface- Heap<K>
- Parameters:
- key- the key to insert
- Throws:
- IllegalArgumentException- if the key is null
- IllegalArgumentException- if the key is less than the minimum allowed key
- IllegalArgumentException- if the key is more than the maximum allowed key
- IllegalArgumentException- if the key is less than the last deleted key (or the minimum key allowed if no key has been deleted)
 
 - 
deleteMinpublic K deleteMin() Delete and return an element with the minimum key. If multiple such elements exists, only one of them will be deleted. The cost of this operation is amortized O(logC) assuming the heap contains keys in the range [0, C] or equivalently [a, a+C].
 - 
isEmptypublic boolean isEmpty() Returnstrueif this heap is empty.
 - 
sizepublic long size() Returns the number of elements in this heap.
 - 
clearpublic void clear() Clear all the elements of this heap.
 - 
comparatorpublic Comparator<? super K> comparator() Always returnsnullsince this heap uses the natural ordering of its keys.- Specified by:
- comparatorin interface- Heap<K>
- Returns:
- nullsince this heap uses the natural ordering of its keys
 
 
- 
 
-