net.rim.device.api.collection.util
Class BigIntVector

Vector optimized to support insert/delete operations without shuffling the
entire array.

The insert/delete operations are accomplished by sorting the elements in
variable sized sub-arrays, or "chunks". Additionally, the underlying vector
can be made contiguous for intensive operations, like sorting.

BigIntVector

Constructs a new empty vector with the specified initial capacity and chunk size.

Parameters:

initialCapacity - Initial capacity of the vector.

chunkSize - Size of each chunk.

BigIntVector

public BigIntVector(int initialCapacity)

Constructs a new empty vector with the specified initial capacity and chunk size.

Parameters:

initialCapacity - Initial capacity of the vector.

BigIntVector

public BigIntVector()

Constructs a new empty vector.

Method Detail

size

public int size()

Returns the number of elements in this vector.

Returns:

Size of this vector.

getContiguousArray

public int[] getContiguousArray()

Returns a contiguous array representation of this vector.

The underlying storage of the container can be a series of variable-sized
sub-arrays, this method consolidates all of the storage into one array.
The returned array should be treated as read-only, any modification
of the array could disrupt the behaviour of the container.

Returns:

Contiguous array representation of this vector.
The array may be bigger than the vector size.

Since:

BlackBerry API 4.0.0

optimize

public void optimize()

Optimize this vector for fast element access by turning the underlying representation
into a contiguous array.

To improve this vector's performance, invoke this method after doing many insertions
and/or deletions.

insertElementsAt

public void insertElementsAt(int[] array,
int index)

Inserts a number of elements at index.

This method adds a number of elements, the first at your specified index. The
existing element at that position, and all the elements beyond it, are shifted up
a number of slots equal to the size of the array inserted.

Parameters:

array - Elements to insert.

index - Position new element should occupy; must be at least 0
and less than the size of this vector.

copyInto

Fills an array with elements from the vector.
The destination array must be large enough to hold all of the copied elements,
starting at position dstPosition.

Parameters:

offset - The offset into the vector of the first element to be copied.

len - The number of elements to read from the vector.

array - The array to fill with the copied elements.

dstPosition - The position in the destination array at which to begin
storing the copied elements.

Returns:

The number of elements read from the vector.

binarySearch

public int binarySearch(int value)

Performs a binary search to locate a value.

This method fails if this vector is not sorted in ascending integer
order.

Parameters:

value - Value to search for.

Returns:

The index of the found value, if contained in the vector. If the
value is not contained in the vector, then this method returns
( -( insertPoint + 1 ) ); the insert point is the position the
value would occupy in the vector.