de.torstennahm.integrate.sparse.index
Interface Index

All Superinterfaces:
java.lang.Iterable<de.torstennahm.math.IntEntry>
All Known Implementing Classes:
FastIndex, StackedIndex

public interface Index
extends java.lang.Iterable<de.torstennahm.math.IntEntry>

Models a multi-index of infinite dimension. The multi-index is an element of the N-fold direct sum of N, where N is the natural numbers including 0.

An index is immutable. Changing the value of an entry will return a new index with the specified change, but leave the original index untouched.

All implementations of this interface must be thread-safe.

Author:
Torsten Nahm

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.
 

Method Detail

nonZeroEntries

int nonZeroEntries()
Returns the number of entries with values not equal to 0.

Returns:
number of entries with value != 0

lastEntry

int lastEntry()
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

int get(int number)
Returns the value for the specified entry.

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

set

Index set(int entryNum,
          int value)
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

Index add(int entryNum,
          int increment)
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

int sum()
Returns the the sum of all entry values.

Returns:
length of the index

iterator

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

Specified by:
iterator in interface java.lang.Iterable<de.torstennahm.math.IntEntry>
Returns:
iterator iterator over the non-zero entries

equals

boolean equals(java.lang.Object o)
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.

Overrides:
equals in class java.lang.Object

hashCode

int hashCode()
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.

Overrides:
hashCode in class java.lang.Object