shh.csparse
Class SparseEltZInt

Object
  extended bySparseElt
      extended bySparseEltEuc
          extended bySparseEltZ
              extended bySparseEltZInt
All Implemented Interfaces:
Comparable

public final class SparseEltZInt
extends SparseEltZ

Elements of a sparse vector over Z, using int to store the values. If an operation would cause the ints to overflow, we automatically return a larger type of SparseEltZ.

Author:
Mark McConnell

Field Summary
protected  int val
          The value of this entry in a sparse vector.
 
Fields inherited from class SparseEltZ
NEG_ONE, ONE, ZERO
 
Fields inherited from class SparseElt
INDEX_SORTER
 
Method Summary
 SparseEltZ abs()
          Returns a SparseEltZ whose value is the absolute value of the value of this, and whose index is that of this.
 SparseElt add(SparseElt y)
          Returns a SparseElt whose value is the sum of the values in this and y, and whose index is that of this.
 int bitLength()
          If the value is a BigInteger, returns its BigInteger.bitLength(); if the value is stored in a primitive type, returns the bit length of the type.
 int compareTo(Object o)
          Compares SparseEltZs by < on the values.
 SparseElt copy(int indexOfCopy)
          Returns a SparseElt with the same value as this, and with index indexOfCopy.
 SparseEltField copyMod(int p, BigInteger pBig)
          Returns this mod p, preserving the index.
 SparseEltZ[] divideAndRemainder(SparseEltZ y)
          Computes this/y and returns a two-element array with values quotient and remainder.
 boolean divides(SparseElt y)
          Whether the value of this divides the value of y; that is, whether there is an x such that x * this = y.
 Number eucNorm()
          Returns the absolute value of the value, as a BigInteger.
 String getPrintValue()
          Returns the value in human-readable form.
 BigInteger getValueAsBigInteger()
          Returns the value as a BigInteger.
 double getValueAsDouble()
          Returns the value as a double.
 int getValueAsInt()
          Coerces the value into an int and returns it.
 boolean isNegOne()
          Whether the value is -1.
 boolean isOne()
          Whether the value is one.
 boolean isZero()
          Whether the value is zero.
 SparseElt multiply(int newIndex, SparseElt y)
          Returns a SparseElt with index newIndex and whose value is the product of the values in this and y.
 SparseElt negate()
          Returns a SparseElt whose value is the negative of the value of this, and whose index is that of this.
 SparseEltEuc negClosestQuotient(SparseEltEuc y)
          Negative of the closest quotient: returns q such that q * y + this is as small as possible for eucNorm().
 int signum()
          Returns -1, 0, or 1 as the value is negative, zero, or positive.
 SparseElt subtract(SparseElt y)
          Returns a SparseElt whose value is (value of this) minus (value of y), and whose index is that of this.
 
Methods inherited from class SparseEltZ
getEucNormComparator, getNegOne, getOne, getZero, hashCode, isEqualValue, makeInstance, makeInstance
 
Methods inherited from class SparseElt
equals, getIndex, multiply, toString
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

val

protected int val
The value of this entry in a sparse vector.

Method Detail

abs

public SparseEltZ abs()
Description copied from class: SparseEltZ
Returns a SparseEltZ whose value is the absolute value of the value of this, and whose index is that of this.

Specified by:
abs in class SparseEltZ

add

public SparseElt add(SparseElt y)
Description copied from class: SparseElt
Returns a SparseElt whose value is the sum of the values in this and y, and whose index is that of this.

Specified by:
add in class SparseElt

bitLength

public final int bitLength()
Description copied from class: SparseElt
If the value is a BigInteger, returns its BigInteger.bitLength(); if the value is stored in a primitive type, returns the bit length of the type.

Specified by:
bitLength in class SparseElt

compareTo

public int compareTo(Object o)
Description copied from class: SparseEltZ
Compares SparseEltZs by < on the values. Use SparseElt.INDEX_SORTER to compare on the indices.

Specified by:
compareTo in interface Comparable
Specified by:
compareTo in class SparseEltZ

copy

public SparseElt copy(int indexOfCopy)
Description copied from class: SparseElt
Returns a SparseElt with the same value as this, and with index indexOfCopy.

Specified by:
copy in class SparseElt

copyMod

public SparseEltField copyMod(int p,
                              BigInteger pBig)
Description copied from class: SparseEltZ
Returns this mod p, preserving the index. Returns null if the value mod p is 0.

Specified by:
copyMod in class SparseEltZ
Parameters:
p - A prime. The user should check it with SparseEltModp.checkP(int).
pBig - p as a BigInteger.

divideAndRemainder

public SparseEltZ[] divideAndRemainder(SparseEltZ y)
Description copied from class: SparseEltZ
Computes this/y and returns a two-element array with values quotient and remainder. Each index is the index of this.

Specified by:
divideAndRemainder in class SparseEltZ

divides

public boolean divides(SparseElt y)
Description copied from class: SparseElt
Whether the value of this divides the value of y; that is, whether there is an x such that x * this = y.

Specified by:
divides in class SparseElt

eucNorm

public Number eucNorm()
Returns the absolute value of the value, as a BigInteger.

Specified by:
eucNorm in class SparseEltEuc

getPrintValue

public String getPrintValue()
Description copied from class: SparseElt
Returns the value in human-readable form.

Specified by:
getPrintValue in class SparseElt

getValueAsDouble

public double getValueAsDouble()
Description copied from class: SparseEltZ
Returns the value as a double.

Specified by:
getValueAsDouble in class SparseEltZ

getValueAsInt

public int getValueAsInt()
Description copied from class: SparseEltZ
Coerces the value into an int and returns it. In other words, returns the value modulo 232.

Specified by:
getValueAsInt in class SparseEltZ

getValueAsBigInteger

public BigInteger getValueAsBigInteger()
Description copied from class: SparseEltZ
Returns the value as a BigInteger. In principle, this is the only accurate way to get the value, but it may consume memory unnecessarily if this is not a SparseEltZBig. Compare SparseEltZ.getValueAsInt().

Specified by:
getValueAsBigInteger in class SparseEltZ

isNegOne

public boolean isNegOne()
Description copied from class: SparseElt
Whether the value is -1.

Specified by:
isNegOne in class SparseElt

isOne

public boolean isOne()
Description copied from class: SparseElt
Whether the value is one.

Specified by:
isOne in class SparseElt

isZero

public boolean isZero()
Description copied from class: SparseElt
Whether the value is zero.

Specified by:
isZero in class SparseElt

multiply

public SparseElt multiply(int newIndex,
                          SparseElt y)
Description copied from class: SparseElt
Returns a SparseElt with index newIndex and whose value is the product of the values in this and y.

Specified by:
multiply in class SparseElt

negate

public SparseElt negate()
Description copied from class: SparseElt
Returns a SparseElt whose value is the negative of the value of this, and whose index is that of this.

Specified by:
negate in class SparseElt

negClosestQuotient

public SparseEltEuc negClosestQuotient(SparseEltEuc y)
Description copied from class: SparseEltEuc
Negative of the closest quotient: returns q such that q * y + this is as small as possible for SparseEltEuc.eucNorm(). In other words, returns -this/y rounded off to the nearest element of D. The index is that of this.

Specified by:
negClosestQuotient in class SparseEltEuc

signum

public final int signum()
Description copied from class: SparseEltZ
Returns -1, 0, or 1 as the value is negative, zero, or positive.

Specified by:
signum in class SparseEltZ

subtract

public SparseElt subtract(SparseElt y)
Description copied from class: SparseElt
Returns a SparseElt whose value is (value of this) minus (value of y), and whose index is that of this.

Specified by:
subtract in class SparseElt