SciLib.Math
Class byteVector

java.lang.Object
  extended by SciLib.Math.byteVector

public class byteVector
extends java.lang.Object

This class defines a dynamic vector of type intger.


Constructor Summary
byteVector()
          Allocates an empty vector.
byteVector(byte[] vec)
          Allocates a vector from the array vec.
byteVector(byteVector x)
          Make a copy of the vector x.
byteVector(int n)
          Allocates a vector of size n with initiařized values 0.
byteVector(java.lang.String s)
          Make a byteVector from s String s.
 
Method Summary
 void add(byte x)
          Add a byte x to the vector.
 void add(short x)
          Add a short value x to the vector.
 void append(byteVector x)
          Append an byteVector x to this vector
 int argmax()
          Compute the index of the maximum element in the vector.
 int argmin()
          Compute the index of the minimum element in the vector.
static byte BitsNeeded(int n)
           
static int byteValue(byte b)
          get the value of a byte
 void concat(byteVector x)
          Append a vector x to this vector
static byteVector copy(byteVector x)
          Make a copy of the vector x.
 byte elementAt(int i)
          return the value of vector at index i.
static vector generate(int from, int to)
          create a uniform vector that has elements from an integer "from" to an integer "to".
 byte[] getData()
          Make an intger array that contains all data of the vector.
 int max()
          return the maximum value of the vector.
 int min()
          return the minimum value of the vector.
static byteVector ones(int n)
          Make a vector of length n whose elements have value 1.
 void print()
          Print all elements of the vector using System.out.
 void read(java.io.InputStream in, int n)
          read n bytes from an InputStream to a byteVector
 void read(java.lang.String fileName)
          Read data from a file to an integer vector.
static byte readByte(java.io.InputStream in)
          read byte
static short readShort(java.io.InputStream in)
          read short
 void resize(int n)
          Change the size of the vector to n.
 void setElementAt(byte x, int i)
          change the value of element at index i with the integer x.
 int size()
          Return the length of the vector.
 byteVector subvector(int from)
          make a vector whose elements are equal to elements of this vector with the indexes from an integer "from" to the end of this vector.
 byteVector subvector(int from, int to)
          Make a vector whose elements are equal to elements of this vector with the indexes from an integer "from" to an intger "to".
 java.lang.String toString()
          create a String that contains the elements of the vector.
 void translate(int s)
          plus all elements of the vector with an integer factor s.
 void trimToSize()
          Remove all the unused elements of the vector.
 int value()
           
 void write(java.io.OutputStream out)
          write an byteVector to an OutputStream
 void write(java.lang.String fileName)
          write an byteVector to a file
static byteVector zeros(int n)
          Make a vector of length n whose elements have value 0.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

byteVector

public byteVector()
Allocates an empty vector.


byteVector

public byteVector(int n)
Allocates a vector of size n with initiařized values 0.

Parameters:
n - The length of the vector

byteVector

public byteVector(byte[] vec)
Allocates a vector from the array vec.

Parameters:
vec - An array of type double

byteVector

public byteVector(java.lang.String s)
Make a byteVector from s String s.

Parameters:
s - A String

byteVector

public byteVector(byteVector x)
Make a copy of the vector x.

Parameters:
x - An byteVector
Method Detail

copy

public static byteVector copy(byteVector x)
Make a copy of the vector x.

Parameters:
x - An byteVector

add

public void add(byte x)
Add a byte x to the vector.

Parameters:
x - A byte value

add

public void add(short x)
Add a short value x to the vector.

Parameters:
x - A short value

append

public void append(byteVector x)
Append an byteVector x to this vector

Parameters:
x - A vector

argmax

public final int argmax()
Compute the index of the maximum element in the vector.

Returns:
An integer

argmin

public final int argmin()
Compute the index of the minimum element in the vector.

Returns:
An integer

concat

public void concat(byteVector x)
Append a vector x to this vector

Parameters:
x - A vector

elementAt

public byte elementAt(int i)
               throws java.lang.ArrayIndexOutOfBoundsException
return the value of vector at index i.

Parameters:
i - An integer
Throws:
java.lang.ArrayIndexOutOfBoundsException

generate

public static vector generate(int from,
                              int to)
create a uniform vector that has elements from an integer "from" to an integer "to".

Parameters:
from - An integer
to - An integer
Returns:
A vector

getData

public byte[] getData()
Make an intger array that contains all data of the vector.

Returns:
An intger array

max

public final int max()
return the maximum value of the vector.

Returns:
An integer value

min

public final int min()
return the minimum value of the vector.

Returns:
An integer value

ones

public static byteVector ones(int n)
Make a vector of length n whose elements have value 1.


print

public void print()
Print all elements of the vector using System.out.


resize

public void resize(int n)
Change the size of the vector to n.

Parameters:
n - The new length of the vector

setElementAt

public void setElementAt(byte x,
                         int i)
                  throws java.lang.ArrayIndexOutOfBoundsException
change the value of element at index i with the integer x.

Parameters:
x - An integer value
i - An index integer
Throws:
java.lang.ArrayIndexOutOfBoundsException

size

public final int size()
Return the length of the vector.

Returns:
An integer

subvector

public byteVector subvector(int from,
                            int to)
Make a vector whose elements are equal to elements of this vector with the indexes from an integer "from" to an intger "to".

Parameters:
from - start index
to - end index
Returns:
A vector

subvector

public byteVector subvector(int from)
make a vector whose elements are equal to elements of this vector with the indexes from an integer "from" to the end of this vector.

Parameters:
from - start index
Returns:
A vector

toString

public java.lang.String toString()
create a String that contains the elements of the vector.

Overrides:
toString in class java.lang.Object
Returns:
A String

translate

public void translate(int s)
plus all elements of the vector with an integer factor s.

Parameters:
s - A double value

trimToSize

public void trimToSize()
Remove all the unused elements of the vector.


zeros

public static byteVector zeros(int n)
Make a vector of length n whose elements have value 0.

Parameters:
n - An integer

write

public void write(java.lang.String fileName)
write an byteVector to a file

Parameters:
fileName - A String

read

public void read(java.lang.String fileName)
Read data from a file to an integer vector.

Parameters:
fileName - a String

write

public void write(java.io.OutputStream out)
write an byteVector to an OutputStream

Parameters:
out - An OutputStream

read

public void read(java.io.InputStream in,
                 int n)
read n bytes from an InputStream to a byteVector

Parameters:
in - An InputStream

readShort

public static short readShort(java.io.InputStream in)
read short

Parameters:
in - An InputStream

readByte

public static byte readByte(java.io.InputStream in)
read byte

Parameters:
in - An InputStream

byteValue

public static int byteValue(byte b)
get the value of a byte

Parameters:
b - A byte
Returns:
an integer

value

public int value()

BitsNeeded

public static byte BitsNeeded(int n)