Package weka.core.matrix
Class IntVector
java.lang.Object
weka.core.matrix.IntVector
- All Implemented Interfaces:
Cloneable
,RevisionHandler
A vector specialized on integers.
- Version:
- $Revision: 8034 $
- Author:
- Yong Wang
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
capacity()
Returns the capacity of the vectorclone()
Clones the IntVector object.copy()
Makes a deep copy of the vectorint
get
(int i) Gets the value of an element.int[]
getArray()
Access the internal one-dimensional array.int[]
Returns a copy of the internal one-dimensional array.Returns the revision string.boolean
isEmpty()
Returns true if the vector is emptystatic void
Tests the IntVector classstatic IntVector
seq
(int i0, int i1) Generates an IntVector that stores all integers inclusively between two integers.void
set
(int s) Sets the value of an element.void
set
(int i, int s) Sets a single element.void
set
(int i0, int i1, int[] v, int j0) Sets the values of elements from an int array.void
Sets the values of elements from another IntVector.void
Sets the values of elements from another IntVector.void
setCapacity
(int capacity) Sets the capacity of the vectorvoid
setSize
(int size) Sets the size of the vector.void
shift
(int i, int j) Shifts an element to another position.void
shiftToEnd
(int j) Shifts an element to the end of the vector.int
size()
Gets the size of the vector.void
sort()
Sorts the elements in placesubvector
(int i0, int i1) Returns a subvector.Returns a subvector as indexed by an IntVector.void
swap
(int i, int j) Swaps the values stored at i and jtoString()
Converts the IntVecor to a stringtoString
(int digits, boolean trailing) Convert the IntVecor to a string
-
Constructor Details
-
IntVector
public IntVector()Constructs a null vector. -
IntVector
public IntVector(int n) Constructs an n-vector of zeros.- Parameters:
n
- Length.
-
IntVector
public IntVector(int n, int s) Constructs an n-vector of a constant- Parameters:
n
- Length.
-
IntVector
public IntVector(int[] v) Constructs a vector given an int array- Parameters:
v
- the int array
-
-
Method Details
-
size
public int size()Gets the size of the vector.- Returns:
- Size.
-
setSize
public void setSize(int size) Sets the size of the vector. The provided size can't be greater than the capacity of the vector.- Parameters:
size
- the new Size.
-
set
public void set(int s) Sets the value of an element.- Parameters:
s
- the value for the element
-
set
public void set(int i0, int i1, int[] v, int j0) Sets the values of elements from an int array.- Parameters:
i0
- the index of the first elementi1
- the index of the last elementv
- the int array that stores the valuesj0
- the index of the first element in the int array
-
set
Sets the values of elements from another IntVector.- Parameters:
i0
- the index of the first elementi1
- the index of the last elementv
- the IntVector that stores the valuesj0
- the index of the first element in the IntVector
-
set
Sets the values of elements from another IntVector.- Parameters:
v
- the IntVector that stores the values
-
seq
Generates an IntVector that stores all integers inclusively between two integers.- Parameters:
i0
- the first integeri1
- the second integer
-
getArray
public int[] getArray()Access the internal one-dimensional array.- Returns:
- Pointer to the one-dimensional array of vector elements.
-
sort
public void sort()Sorts the elements in place -
getArrayCopy
public int[] getArrayCopy()Returns a copy of the internal one-dimensional array.- Returns:
- One-dimensional array copy of vector elements.
-
capacity
public int capacity()Returns the capacity of the vector -
setCapacity
public void setCapacity(int capacity) Sets the capacity of the vector- Parameters:
capacity
- the new capacity of the vector
-
set
public void set(int i, int s) Sets a single element.- Parameters:
i
- the index of the elements
- the new value
-
get
public int get(int i) Gets the value of an element.- Parameters:
i
- the index of the element- Returns:
- the value of the element
-
copy
Makes a deep copy of the vector -
clone
Clones the IntVector object. -
subvector
Returns a subvector.- Parameters:
i0
- the index of the first elementi1
- the index of the last element- Returns:
- the subvector
-
subvector
Returns a subvector as indexed by an IntVector.- Parameters:
index
- the index- Returns:
- the subvector
-
swap
public void swap(int i, int j) Swaps the values stored at i and j- Parameters:
i
- the index ij
- the index j
-
shift
public void shift(int i, int j) Shifts an element to another position. Elements between them are shifted one position left.- Parameters:
i
- the index of the elementj
- the index of the new position
-
shiftToEnd
public void shiftToEnd(int j) Shifts an element to the end of the vector. Elements between them are shifted one position left.- Parameters:
j
- the index of the element
-
isEmpty
public boolean isEmpty()Returns true if the vector is empty -
toString
Converts the IntVecor to a string -
toString
Convert the IntVecor to a string- Parameters:
digits
- number of digits to be showntrailing
- true if trailing zeros are to be shown
-
getRevision
Returns the revision string.- Specified by:
getRevision
in interfaceRevisionHandler
- Returns:
- the revision
-
main
Tests the IntVector class
-