Class IntVector

java.lang.Object
weka.core.matrix.IntVector
All Implemented Interfaces:
Cloneable, RevisionHandler

public class IntVector extends Object implements Cloneable, RevisionHandler
A vector specialized on integers.
Version:
$Revision: 8034 $
Author:
Yong Wang
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a null vector.
    IntVector(int n)
    Constructs an n-vector of zeros.
    IntVector(int[] v)
    Constructs a vector given an int array
    IntVector(int n, int s)
    Constructs an n-vector of a constant
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the capacity of the vector
    Clones the IntVector object.
    Makes a deep copy of the vector
    int
    get(int i)
    Gets the value of an element.
    int[]
    Access the internal one-dimensional array.
    int[]
    Returns a copy of the internal one-dimensional array.
    Returns the revision string.
    boolean
    Returns true if the vector is empty
    static void
    main(String[] args)
    Tests the IntVector class
    static 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
    set(int i0, int i1, IntVector v, int j0)
    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 vector
    void
    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
    Gets the size of the vector.
    void
    Sorts the elements in place
    subvector(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 j
    Converts the IntVecor to a string
    toString(int digits, boolean trailing)
    Convert the IntVecor to a string

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 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 element
      i1 - the index of the last element
      v - the int array that stores the values
      j0 - the index of the first element in the int array
    • set

      public void set(int i0, int i1, IntVector v, int j0)
      Sets the values of elements from another IntVector.
      Parameters:
      i0 - the index of the first element
      i1 - the index of the last element
      v - the IntVector that stores the values
      j0 - the index of the first element in the IntVector
    • set

      public void set(IntVector v)
      Sets the values of elements from another IntVector.
      Parameters:
      v - the IntVector that stores the values
    • seq

      public static IntVector seq(int i0, int i1)
      Generates an IntVector that stores all integers inclusively between two integers.
      Parameters:
      i0 - the first integer
      i1 - 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 element
      s - 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

      public IntVector copy()
      Makes a deep copy of the vector
    • clone

      public Object clone()
      Clones the IntVector object.
    • subvector

      public IntVector subvector(int i0, int i1)
      Returns a subvector.
      Parameters:
      i0 - the index of the first element
      i1 - the index of the last element
      Returns:
      the subvector
    • subvector

      public IntVector subvector(IntVector index)
      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 i
      j - 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 element
      j - 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

      public String toString()
      Converts the IntVecor to a string
      Overrides:
      toString in class Object
    • toString

      public String toString(int digits, boolean trailing)
      Convert the IntVecor to a string
      Parameters:
      digits - number of digits to be shown
      trailing - true if trailing zeros are to be shown
    • getRevision

      public String getRevision()
      Returns the revision string.
      Specified by:
      getRevision in interface RevisionHandler
      Returns:
      the revision
    • main

      public static void main(String[] args)
      Tests the IntVector class