Class DoubleRadixHeap
- All Implemented Interfaces:
Serializable
,Heap<Double>
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.
- See Also:
-
Field Summary
FieldsFields inherited from class org.jheaps.monotone.AbstractRadixHeap
buckets, currentMin, currentMinBucket, currentMinPos, EMPTY, lastDeletedKey, maxKey, minKey, size
-
Constructor Summary
ConstructorsConstructorDescriptionDoubleRadixHeap
(double minKey, double maxKey) Constructs a new heap which can store values between a minimum and a maximum key value (inclusive). -
Method Summary
Methods inherited from class org.jheaps.monotone.AbstractRadixHeap
clear, comparator, computeBucket, deleteMin, findMin, insert, isEmpty, size
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
-
Constructor Details
-
DoubleRadixHeap
public DoubleRadixHeap(double minKey, double 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 operationdeleteMin
requires 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 negativeIllegalArgumentException
- if the maximum key is less than the minimum key
-
-
Method Details
-
compare
Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.- Specified by:
compare
in classAbstractRadixHeap<Double>
- Parameters:
o1
- the first object to be compared.o2
- the second object to be compared.- Returns:
- a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
-
msd
Compute the most significant digit which is different in the binary representation of two values, or -1 if numbers are equal.- Specified by:
msd
in classAbstractRadixHeap<Double>
- Parameters:
a
- the first valueb
- the second value- Returns:
- the most significant digit which is different or -1 if numbers are equal
-