|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--ostore.oil.Matrix
A sparse array of Array
s. Elements are indexed by
arbitrary QuickSerializable
objects.
This class is synchronized.
Field Summary | |
---|---|
protected HashMap |
map
The internal storage mechanism. |
Constructor Summary | |
---|---|
Matrix()
Construct a new Matrix . |
|
Matrix(InputBuffer buffer)
Implied from ostore.util.QuickSerializable interface Construct an Matrix from its
QuickSerializable form. |
|
Matrix(InputBuffer buffer,
HashMap decompression_map,
HashMap row_decompression_map)
Construct an Matrix from its
QuickSerializable form.
|
Method Summary | |
---|---|
void |
add(Matrix addend)
Adds the contents of the specified Matrix to this one.
|
void |
add(QuickSerializable id,
Array addend)
Adds the specified Array to this Matrix .
|
Object |
clone()
Performs a slightly deeper copy than Object.clone .
|
boolean |
contains(QuickSerializable id)
Shows whether the specified ID is explicitly stored in this Matrix . |
int |
full_size()
Returns the full size of the Matrix . |
Array |
get(QuickSerializable id)
Returns the Array indexed by the specified ID. |
Iterator |
ids()
Returns an Iterator over the IDs stored explicitly in
this Matrix . |
static void |
max(double[][] matrix,
int[][] indices)
Finds the indices of the largest elements of the specified Matrix. |
Array |
put(QuickSerializable id,
Array row)
Places the specified mapping into this Matrix . |
Array |
remove(QuickSerializable id)
Removes the row associated with id from this
Matrix , and returns the removed row. |
void |
serialize(OutputBuffer buffer)
Add the object to the buffer . |
void |
serialize(OutputBuffer buffer,
HashMap compression_map,
HashMap row_compression_map)
|
int |
size()
Returns the size of the Matrix . |
String |
toString()
Produce a human-readable version of this Matrix .
|
static String |
toString(double[][] matrix)
Returns a human-readable representation of the specified matrix. |
static String |
toString(double[][] matrix,
int[][] indices)
Returns a human-readable representation of the specified matrix, with indices. |
static double[][] |
transpose(double[][] matrix)
Returns the transpose of the specified matrix. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected HashMap map
Constructor Detail |
public Matrix()
Matrix
.
public Matrix(InputBuffer buffer) throws QSException
Matrix
from its
QuickSerializable
form.
public Matrix(InputBuffer buffer, HashMap decompression_map, HashMap row_decompression_map) throws QSException
Matrix
from its
QuickSerializable
form.
See serialize(OutputBuffer, HashMap, HashMap)
for more details.
decompression_map
- An Integer->QuickSerializable
mapping
for decompressing IDs.row_decompression_map
- An Integer->QuickSerializable
mapping for decompressing IDs within rows.Method Detail |
public static String toString(double[][] matrix)
matrix
- the matrix to print
public static String toString(double[][] matrix, int[][] indices)
Array.toString(double[], int[])
on
each row of the matrix.
matrix
- the matrix to printindices
- the indices, in order, of the elements to print
IllegalArgumentException
- if width of indices
greater than width of corresponding row of matrix
.
See Also:
max(double[][], int[][])
transpose
public static final double[][] transpose(double[][] matrix)
- Returns the transpose of the specified matrix.
The width of the new matrix is the length of the specified matrix,
and vice versa. WARNING This method is in some ways even more
expensive than
toString
.
- Parameters:
matrix
- the matrix to flip
- Returns:
- the transpose of the specified matrix.
max
public static void max(double[][] matrix,
int[][] indices)
- Finds the indices of the largest elements of the specified Matrix.
This method calls
Array.max(double[], int[])
on each row of the matrix.
Thus the width of indices
determines the number of top
elements of each row to find. To find the top elements of each
column (instead of by row) use transpose
to flip the
matrix first.
- Parameters:
matrix
- the matrix to checkindices
- the matrix into which to put the (sorted) indices of
the largest elements of matrix
.
- Throws:
IllegalArgumentException
- if width of indices
greater than width of corresponding row of matrix
.
size
public int size()
- Returns the size of the
Matrix
.
- Returns:
- the number of
Array
s stored in this
Matrix
.
full_size
public int full_size()
- Returns the full size of the
Matrix
.
- Returns:
- the total number of elements explicitly stored in the
Array
s stored in this Matrix
.
ids
public Iterator ids()
- Returns an
Iterator
over the IDs stored explicitly in
this Matrix
.
- Returns:
- a
HashIterator
over the backing map's keys.
contains
public boolean contains(QuickSerializable id)
- Shows whether the specified ID is explicitly stored in this
Matrix
.
- Parameters:
id
- The unique ID for the row to check.
- Returns:
true
iff id
is explicitly mapped
to a row.
get
public Array get(QuickSerializable id)
- Returns the
Array
indexed by the specified ID.
- Parameters:
id
- The unique ID for a row of this
Matrix
.
- Returns:
- the
Array
stored under id
, or
null
if the ID is unknown.
put
public Array put(QuickSerializable id,
Array row)
- Places the specified mapping into this
Matrix
. If
id
already maps to an Array
, the old one
is replaced and returned.
- Parameters:
id
- The index under which to store this row.row
- The Array
to store for this index.
- Returns:
- the
Array
previously mapped by this index, or
null
if the ID is unknown.
remove
public Array remove(QuickSerializable id)
- Removes the row associated with
id
from this
Matrix
, and returns the removed row. The
specified id
will no longer be associated with
any row in this Matrix
.
- Parameters:
id
- The index to be disassociated from the
Matrix
.
- Returns:
- the
Array
previously associated with the index
being removed, or null
if the index is unknown.
add
public void add(Matrix addend)
- Adds the contents of the specified
Matrix
to this one.
Array
s for known IDs are add
ed to the
current rows. Unknown IDs are inserted directly (not
clone
d).
- Parameters:
addend
- The Matrix
whose contents to add
add
public void add(QuickSerializable id,
Array addend)
- Adds the specified
Array
to this Matrix
.
If the ID is known, the Array
is add
ed to
the current row. Otherwise it is clone
d and inserted.
- Parameters:
id
- The unique ID for addend
addend
- The Array
to add
clone
public Object clone()
- Performs a slightly deeper copy than
Object.clone
.
The mapping is cloned, so the new Matrix
can be modified
independently of this one. Neither the IDs nor the rows are
themselves cloned.
- Overrides:
clone
in class Object
- Returns:
- a new
Matrix
with the same set of elements as
this one.
toString
public String toString()
- Produce a human-readable version of this
Matrix
.
This method consumes O(full_size())
time and
String
length.
- Overrides:
toString
in class Object
- Returns:
- a
String
of < id:row > pairs.
serialize
public void serialize(OutputBuffer buffer)
- Description copied from interface:
QuickSerializable
- Add the object to the
buffer
.
- Specified by:
serialize
in interface QuickSerializable
- Parameters:
buffer
- the output buffer to add the object to
serialize
public void serialize(OutputBuffer buffer,
HashMap compression_map,
HashMap row_compression_map)
Overview
Package
Class
Tree
Serialized
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD