shh.csparse
Class SparseElt

Object
  extended bySparseElt
Direct Known Subclasses:
SparseEltEuc

public abstract class SparseElt
extends Object

An abstract class representing elements of a sparse vector (a SparseV) over an integral domain D. A SparseElt is an immutable ordered pair consisting of an index and an element of D. The index is the index in the sparse vector. It must be ≥ 0. The implementation will determine which domain is used.

A SparseElt may have value zero, but it is an error if such a SparseElt becomes an element of a SparseV. (As a corollary, we require 0 ≠ 1 in D.)

Some implementations will have public constructors. Others will have static makeInstance methods.

When possible, implementations should implement Comparable to compare SparseElts by < on their values. Examples are when D is a subring of the real numbers R or some other ordered field. To compare on the indices, use INDEX_SORTER.

Author:
Mark McConnell

Field Summary
static Comparator INDEX_SORTER
          Compares two SparseElts by < on the indices.
static SparseElt NEG_ONE
          A formal "-1" object that can be combined in arithmetic operations with elements from another domain (a "complete" implementation of SparseElt), producing values in the other domain.
static SparseElt ONE
          A formal "1" object that can be combined in arithmetic operations with elements from another domain (a "complete" implementation of SparseElt), producing values in the other domain.
static SparseElt ZERO
          A formal "0" object that can be combined in arithmetic operations with elements from another domain (a "complete" implementation of SparseElt), producing values in the other domain.
 
Constructor Summary
SparseElt()
           
 
Method Summary
abstract  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.
abstract  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.
abstract  SparseElt copy(int indexOfCopy)
          Returns a SparseElt with the same value as this, and with index indexOfCopy.
abstract  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.
 boolean equals(Object o)
          Says two SparseElts are equal if and only if they have the same index and satisfy isEqualValue(shh.csparse.SparseElt).
 int getIndex()
          Returns the index.
abstract  SparseElt getNegOne()
          Returns a SparseElt from the same integral domain as this, with value -1 and unspecified index.
abstract  SparseElt getOne()
          Returns a SparseElt from the same integral domain as this, with value 1 and unspecified index.
abstract  String getPrintValue()
          Returns the value in human-readable form.
abstract  SparseElt getZero()
          Returns a SparseElt from the same integral domain as this, with value 0 and unspecified index.
abstract  int hashCode()
          Must be consistent with equals(java.lang.Object).
abstract  boolean isEqualValue(SparseElt y)
          Tests whether the values are equal, ignoring the indices.
abstract  boolean isNegOne()
          Whether the value is -1.
abstract  boolean isOne()
          Whether the value is one.
abstract  boolean isZero()
          Whether the value is zero.
abstract  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 multiply(SparseElt y)
          Returns a SparseElt whose value is the product of the values in this and y, and whose index is that of this.
abstract  SparseElt negate()
          Returns a SparseElt whose value is the negative of the value of this, and whose index is that of this.
abstract  SparseElt subtract(SparseElt y)
          Returns a SparseElt whose value is (value of this) minus (value of y), and whose index is that of this.
 String toString()
          Returns (index value).
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

INDEX_SORTER

public static final Comparator INDEX_SORTER
Compares two SparseElts by < on the indices.


ZERO

public static final SparseElt ZERO
A formal "0" object that can be combined in arithmetic operations with elements from another domain (a "complete" implementation of SparseElt), producing values in the other domain. Operations that wouldn't produce results in a "complete" implementation are unsupported.


ONE

public static final SparseElt ONE
A formal "1" object that can be combined in arithmetic operations with elements from another domain (a "complete" implementation of SparseElt), producing values in the other domain. Operations that wouldn't produce results in a "complete" implementation are unsupported.


NEG_ONE

public static final SparseElt NEG_ONE
A formal "-1" object that can be combined in arithmetic operations with elements from another domain (a "complete" implementation of SparseElt), producing values in the other domain. Operations that wouldn't produce results in a "complete" implementation are unsupported.

Constructor Detail

SparseElt

public SparseElt()
Method Detail

add

public abstract 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.


bitLength

public abstract 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.


copy

public abstract SparseElt copy(int indexOfCopy)
Returns a SparseElt with the same value as this, and with index indexOfCopy.


divides

public abstract 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.

Throws:
ArithmeticException - If this is zero.

equals

public boolean equals(Object o)
Says two SparseElts are equal if and only if they have the same index and satisfy isEqualValue(shh.csparse.SparseElt).


getIndex

public int getIndex()
Returns the index.


getNegOne

public abstract SparseElt getNegOne()
Returns a SparseElt from the same integral domain as this, with value -1 and unspecified index.


getOne

public abstract SparseElt getOne()
Returns a SparseElt from the same integral domain as this, with value 1 and unspecified index.


getPrintValue

public abstract String getPrintValue()
Returns the value in human-readable form.


getZero

public abstract SparseElt getZero()
Returns a SparseElt from the same integral domain as this, with value 0 and unspecified index.


hashCode

public abstract int hashCode()
Must be consistent with equals(java.lang.Object).


isEqualValue

public abstract boolean isEqualValue(SparseElt y)
Tests whether the values are equal, ignoring the indices.


isNegOne

public abstract boolean isNegOne()
Whether the value is -1.


isOne

public abstract boolean isOne()
Whether the value is one.


isZero

public abstract boolean isZero()
Whether the value is zero.


multiply

public SparseElt multiply(SparseElt y)
Returns a SparseElt whose value is the product of the values in this and y, and whose index is that of this.


multiply

public abstract 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.


negate

public abstract SparseElt negate()
Returns a SparseElt whose value is the negative of the value of this, and whose index is that of this.


subtract

public abstract SparseElt subtract(SparseElt y)
Returns a SparseElt whose value is (value of this) minus (value of y), and whose index is that of this.


toString

public String toString()
Returns (index value).