public class SparseByteVector extends Object
Long.MAX_VALUE
(i.e. 9223372036854775807). The
maximum number of counts larger than zero that can be stored is
Integer.MAX_VALUE
(i.e. 2147483647).Constructor and Description 

SparseByteVector(long length)
Creates a new vector with (initially) space for 64 counts and of the
specified length.

SparseByteVector(long length,
int initialCapacity)
Creates a new vector of the specified length and with (initially) space
for the specified number of counts.

SparseByteVector(long length,
long[] countIndices,
byte[] counts)
Creates a new instance by taking over the initialization from the passed
arrays.

SparseByteVector(SparseByteVector byteVector)
Creates a clone of the passed vector.

Modifier and Type  Method and Description 

SparseByteVector 
add(SparseByteVector bv,
boolean remainder)
Returns a new vector with the sum of the counts at each position.

int 
cardinality()
Returns the number of counts larger than zero stored in this vector.

void 
clear(long index)
Resets the count at the specified index (sets it to zero).

SparseByteVector 
concatenate(SparseByteVector bv)
Creates and returns a new byte vector that contains copies of both (this
and the argument vector).

boolean 
equals(Object obj) 
int 
get(long index)
Returns the number stored at the specified index.

long[] 
getAllCountIndices()
Returns a copy of the internal storage of all values.

byte[] 
getAllCounts()
Returns a copy of the internal storage of all values.

int 
hashCode() 
boolean 
isEmpty()
Checks all counts and returns true if they are all zero.

long 
length()
Returns the number of numbers stored in this vector.

SparseByteVector 
max(SparseByteVector bv)
Returns a new vector with the maximum of the counts at each position.

SparseByteVector 
min(SparseByteVector bv)
Returns a new vector with the minimum of the counts at each position.

long 
nextCountIndex(long startIdx)
Finds the next count not equal to zero on or after the specified index.

long 
nextZeroIndex(long startIdx)
Finds the next index whose value is zero on or after the specified index.

void 
set(long index,
int value)
Stores the number at the specified index.

void 
shrink()
Frees unused memory in the vector.

SparseByteVector 
subSequence(long startIdx,
long endIdx)
Creates and returns a new byte vector that contains a subsequence of this
vector, beginning with the byte at index
startIdx and with
its last byte being this' byte at position endIdx  1 . 
long 
sumOfAllCounts()
Calculates the checksum, the sum of all counts stored.

String 
toString()
Returns a string containing (comma separated) all numbers stored in this
vector.

public SparseByteVector(long length)
length
 the length of the vector to createpublic SparseByteVector(long length, int initialCapacity)
length
 the length of the vector to createinitialCapacity
 space will be allocated to store that many numberspublic SparseByteVector(long length, long[] countIndices, byte[] counts)
countIndices
)
are considered indices of the positions a number is stored at. The second
array (counts
) contains the corresponding number to
store. Both arrays must have the same length.countIndices
array must be sorted! The lowest index
must be stored at array index zero. The arrays must be build like the one
returned by the getAllCountIndices()
and getAllCounts()
methods.length
 the length of the vector. Indices must be smaller than this
number.countIndices
 the array containing the indices of the counts to
store. MUST be sorted (lowest index first).counts
 the numbers to store. Note, even though Java handles
byte
as signed numbers, the passed counts are
interpreted as positive counts in the range of 0 ... 255.IllegalArgumentException
 if length is negative or if the array
contains negative indices or indices larger than length  or
if the array is not sorted or the arrays do not have the same
length!public SparseByteVector(SparseByteVector byteVector)
byteVector
 the vector to clone.public long length()
public void shrink()
public void set(long index, int value)
index
 the index of the position where the count will be stored.value
 the number to store at the specified index. Must be in the
range of 0 ... 255.ArrayIndexOutOfBoundsException
 if the index is negative or larger
than the size of the vector.IllegalArgumentException
 if the specified value is negative or
larger than 255.public void clear(long index)
index
 the index of the position to clear.ArrayIndexOutOfBoundsException
 if the index is negative or larger
than the size of the vectorpublic int cardinality()
public boolean isEmpty()
public int get(long index)
index
 the index of the number to return.ArrayIndexOutOfBoundsException
 if the index is larger than the
length of the vectorpublic long nextCountIndex(long startIdx)
startIdx
 the first index to look for nonzero counts. (It is
allowed to pass an index larger then the vector's length.)ArrayIndexOutOfBoundsException
 if the specified startIdx is
negativepublic long nextZeroIndex(long startIdx)
startIdx
 the first index to look for zero values.ArrayIndexOutOfBoundsException
 if the specified startIdx negativepublic long sumOfAllCounts()
public SparseByteVector add(SparseByteVector bv, boolean remainder)
bv
 the vector to add to this one (positionwise).remainder
 if true and the result of the addition is larger than
255, the value in the result vector will be set to the
remainder when divided by 255  if false, the result vector is
set to 255 if the sum is larger than 255. (Setting it to true
performs slightly better.)public SparseByteVector min(SparseByteVector bv)
bv
 the vector to compute the minimum of (positionwise).public SparseByteVector max(SparseByteVector bv)
bv
 the vector to compute the maximum of (positionwise).public SparseByteVector concatenate(SparseByteVector bv)
bv
 the vector to append at the end of thispublic SparseByteVector subSequence(long startIdx, long endIdx)
startIdx
and with
its last byte being this' byte at position endIdx  1
.
The length of the result vector is endIdx  startIdx
. If
startIdx
equals endIdx
a vector of length
zero is returned.startIdx
 the first index included in the subsequenceendIdx
 the first byte in this vector after startIdx that is not
included in the result sequence.endIdx  startIdx
containing the subsequence of this vector from
startIdx
(included) to endIdx
(not
included anymore).public String toString()
public byte[] getAllCounts()
getAllCountIndices()
. The arrays returned by these two methods
are of same length. The count at index i in the result array is located
in the vector at the index stored in the other array at the same index i.
Note, even though Java stores signed numbers in byte
, the
returned number are values in the range of 0... 255.public long[] getAllCountIndices()