|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.rabbitmq.utility.IntAllocator
public class IntAllocator
A class for allocating integers from a given range that uses a
BitSet
representation of the free integers.
reserve(int)
was expensive in this scheme, whereas in the
present implementation it is O(1), as is free(int)
.
Although allocate()
is slightly slower than O(1) and in the
worst case could be O(N), the use of a "lastIndex
" field
for starting the next scan for free integers means this is negligible.
The data representation overhead is O(N) where N is the size of the
allocation range. One long
is used for every 64 integers in the
range.
Very little Object creation and destruction occurs in use.
Constructor Summary | |
---|---|
IntAllocator(int bottom,
int top)
Creates an IntAllocator allocating integer IDs within the inclusive range [ bottom , top ]. |
Method Summary | |
---|---|
int |
allocate()
Allocate an unallocated integer from the range, or return -1 if no more integers are available. |
void |
free(int reservation)
Make the provided integer available for allocation again. |
boolean |
reserve(int reservation)
Attempt to reserve the provided ID as if it had been allocated. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public IntAllocator(int bottom, int top)
bottom
, top
].
bottom
- lower end of rangetop
- upper end of range (inclusive)Method Detail |
---|
public int allocate()
public void free(int reservation)
reservation
- the previously allocated integer to freepublic boolean reserve(int reservation)
reservation
- the integer to be allocated, if possible
true
if allocated, false
if already allocatedpublic java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |