java.lang.Object | |
↳ | com.rabbitmq.utility.IntAllocator |
A class for allocating integers from a given range that uses a BitSet representation of the free integers.
Concurrent Semantics:allocate()
is slightly slower than O(1) and in the
worst case could be O(N), the use of the #lastIndex field
for starting the next scan for free integers means this is negligible.
long
is used for every 64 integers in the
range.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates an IntAllocator allocating integer IDs within the
inclusive range [
bottom , top ]. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Allocate an unallocated integer from the range, or return -1 if no
more integers are available.
| |||||||||||
Make the provided integer available for allocation again.
| |||||||||||
Attempt to reserve the provided ID as if it had been allocated.
| |||||||||||
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Creates an IntAllocator allocating integer IDs within the
inclusive range [bottom
, top
].
bottom | lower end of range |
---|---|
top | upper end of range (inclusive) |
Allocate an unallocated integer from the range, or return -1 if no more integers are available.
Make the provided integer available for allocation again. This operation
runs in O(1) time.
No error checking is performed, so if you double free or free an
integer that was not originally allocated the results are undefined.
reservation | the previously allocated integer to free |
---|
Attempt to reserve the provided ID as if it had been allocated. Returns
true if it is available, false otherwise.
This operation runs in O(1) time.
reservation | the integer to be allocated, if possible |
---|
true
if allocated, false
if already allocated