de.torstennahm.integrate.sparse.index
Class StackedIndex

java.lang.Object
  extended by de.torstennahm.integrate.sparse.index.StackedIndex
All Implemented Interfaces:
Index, java.lang.Iterable<de.torstennahm.math.IntEntry>

public class StackedIndex
extends java.lang.Object

Implements Index. Only the modification to a parent index is stored. In this way, each index is effectively given as a series of changes to the original 0 index. This makes for a low memory footprint and very fast generation times. However, due to the stacked nature of the indices, the methods getEntry, intPairIterator, nonZeroEntries and equals may be slow. Also, while addEntry is fast, setEntry may be slow. This is due to the fact that modifictations are stored as increments to an entry, not as absolute entry values.

Author:
Torsten Nahm

Constructor Summary
StackedIndex()
           
 
Method Summary
 Index add(int entryNum, int increment)
          Returns a new index with the specified increment at the specified entry.
 boolean equals(java.lang.Object o)
          Compares the specified object with this index for equality.
 int get(int number)
          Returns the value for the specified entry.
 int hashCode()
          Returns the hash code value for this index.
 java.util.Iterator<de.torstennahm.math.IntEntry> iterator()
          Returns an IntPairIterator for iterating over the index.
 int lastEntry()
          Returns the index of highest entry whose value is not 0.
 int nonZeroEntries()
          Returns the number of entries with values not equal to 0.
 Index set(int entryNum, int value)
          Returns a new index with the specified new value at the specified entry.
 int sum()
          Returns the the sum of all entry values.
protected  de.torstennahm.math.SparseIntVector toSparseIntVector()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StackedIndex

public StackedIndex()
Method Detail

nonZeroEntries

public int nonZeroEntries()
Description copied from interface: Index
Returns the number of entries with values not equal to 0.

Returns:
number of entries with value != 0

lastEntry

public int lastEntry()
Description copied from interface: Index
Returns the index of highest entry whose value is not 0.

Returns:
number of last non-0 entry, -1 if all entries are 0

get

public int get(int number)
Description copied from interface: Index
Returns the value for the specified entry.

Parameters:
number - number of the entry
Returns:
value value of the entry

set

public Index set(int entryNum,
                 int value)
Description copied from interface: Index
Returns a new index with the specified new value at the specified entry.

Parameters:
entryNum - number of the entry
value - new value for the entry
Returns:
new index with the requested change

add

public Index add(int entryNum,
                 int increment)
Description copied from interface: Index
Returns a new index with the specified increment at the specified entry.

Parameters:
entryNum - number of the entry
increment - increment for the entry, may be negative
Returns:
new index with the requested change

sum

public int sum()
Description copied from interface: Index
Returns the the sum of all entry values.

Returns:
length of the index

iterator

public java.util.Iterator<de.torstennahm.math.IntEntry> iterator()
Description copied from interface: Index
Returns an IntPairIterator for iterating over the index. The iterator skips all entries whose value is zero.

Returns:
iterator iterator over the non-zero entries

hashCode

public int hashCode()
Description copied from interface: Index
Returns the hash code value for this index. The hash code of an index is defined by the following expression:
hashCode = e[0] * a0 + ... + e[dimension - 1] * a_(dimension-1)
, where e[i] is the i-th entry, and a_i = (i + 13) << i in integer arithmetic.

Specified by:
hashCode in interface Index
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Description copied from interface: Index
Compares the specified object with this index for equality. Returns true if the specified object is also an index, the two indices have the same dimension, and all the entries of the two indices are equal. This definition ensures that the equals method works properly across different implementations of the Index interface.

Specified by:
equals in interface Index
Overrides:
equals in class java.lang.Object

toSparseIntVector

protected de.torstennahm.math.SparseIntVector toSparseIntVector()