|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--ostore.oil.Array
A sparse array of double
s. Elements are indexed by
arbitrary QuickSerializable
objects.
The Array
objects understand the concept of a
default element, which is returned for unknown IDs. Using
this functionality, an Array
could explicitly store only
interesting elements, yet appear to store a full array.
This class is synchronized.
Field Summary | |
---|---|
static double |
DEFAULT_DEFAULT
The default value for default_elt .
|
protected double |
default_elt
The value to return for unknown IDs. |
protected HashMap |
map
The internal storage mechanism. |
Constructor Summary | |
---|---|
Array()
Construct a new Array with the default default. |
|
Array(double default_elt)
Construct a new Array with the specified default. |
|
Array(InputBuffer buffer)
Constructs a Array from its
serialize d form. |
|
Array(InputBuffer buffer,
HashMap decompression_map)
Constructs a Array from its
serialize d form. |
Method Summary | |
---|---|
void |
add(Array addend)
Adds the contents of the specified Array to this one.
|
void |
add(QuickSerializable id,
double value)
Adds the specified value to this Array .
|
void |
clear()
Removes all elements from this Array .
|
Object |
clone()
Performs a slightly deeper copy than Object.clone .
|
boolean |
contains(QuickSerializable id)
Shows whether the specified ID is explicitly stored in this Array . |
double |
get_default()
Returns the value that this Array should return for
unknown IDs. |
double |
get(QuickSerializable id)
Returns the value indexed by the specified ID, or the default element if no such value exists. |
Iterator |
ids()
Returns an Iterator over the IDs stored explicitly in
this Array . |
static void |
max(double[] array,
int[] indices)
Finds the indices of the largest elements of the specified array. |
double |
put(QuickSerializable id,
double value)
Places the specified mapping into this Array . |
double |
remove(QuickSerializable id)
Removes the value indexed by the specified ID |
void |
serialize(OutputBuffer buffer)
Add the object to the buffer . |
void |
serialize(OutputBuffer buffer,
HashMap compression_map)
Serializes the Array using a compression map. |
void |
set_default(double default_elt)
Defines the value that this Array should return for
unknown IDs. |
int |
size()
Returns the size of the Array . |
void |
sparsify(int new_size)
Shrinks this Array to new_size ,
keeping only the largest elements. |
String |
toString()
Produce a human-readable version of this Array . |
static String |
toString(double[] array)
Returns a human-readable representation of the specified array. |
static String |
toString(double[] array,
int[] indices)
Returns a human-readable representation of the specified array, with indices. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final double DEFAULT_DEFAULT
default_elt
.
Currently: Double.Nan
protected double default_elt
protected HashMap map
Constructor Detail |
public Array()
Array
with the default default.
public Array(double default_elt)
Array
with the specified default.
default_elt
- The value to be returned for any unknown IDspublic Array(InputBuffer buffer) throws QSException
Array
from its
serialize
d form.
public Array(InputBuffer buffer, HashMap decompression_map) throws QSException
Array
from its
serialize
d form.
decompression_map
- An Integer->QuickSerializable
mapping
for decompression.Method Detail |
public static String toString(double[] array)
array
- the array to print
public static String toString(double[] array, int[] indices)
array
- the array to printindices
- the indices, in order, of the elements to print
IllegalArgumentException
- if indices.length >
array.length
.max(double[], int[])
public static void max(double[] array, int[] indices)
indices
determines the number of top
elements to find; it must be greater than array.length
.
array
- the array to checkindices
- the array into which to put the (sorted) indices of
the largest elements of array
.
IllegalArgumentException
- if indices.length >
array.length
.public double get_default()
Array
should return for
unknown IDs.
public void set_default(double default_elt)
Array
should return for
unknown IDs.
default_elt
- The value to return for unknown IDs.public int size()
Array
.
Array
.public Iterator ids()
Iterator
over the IDs stored explicitly in
this Array
.
HashIterator
over the backing map's keys.public boolean contains(QuickSerializable id)
Array
.
id
- The unique ID for the element to check.
true
iff id
is explicitly mapped
to a value.public double get(QuickSerializable id)
id
- The unique ID for an element of this
Array
.
id
, or the default
element.public double put(QuickSerializable id, double value)
Array
. If
id
already maps to a value, the old value is
overwritten and returned.
id
- The index under which to store this element.value
- The value to store for this index.
public double remove(QuickSerializable id)
id
- The unique ID for an element of this
Array
.
id
, or the default
element.public void clear()
Array
.
This method does not reset the default return value.
public void add(Array addend)
Array
to this one.
Values for known IDs are added to their current values.
Unknown IDs are added directly (default elements are not considered).
addend
- The Array
whose contents to addpublic void add(QuickSerializable id, double value)
Array
.
If the ID is known, the value is added to the current value.
Otherwise it is inserted as in
put(ostore.util.QuickSerializable, double)
.
id
- The unique ID for value
.value
- The value to add.public void sparsify(int new_size)
Array
to new_size
,
keeping only the largest elements. Ties are broken in an arbitrary,
non-deterministic fashion.
new_size
- The number of elements to keep.public Object clone()
Object.clone
.
The mapping is cloned, so the new Array
can be modified
independently of this one. Neither the IDs nor the values are
themselves cloned.
clone
in class Object
Array
with the same set of elements as
this one.public String toString()
Array
.
toString
in class Object
String
of < id:value > pairs.public void serialize(OutputBuffer buffer)
QuickSerializable
buffer
.
serialize
in interface QuickSerializable
buffer
- the output buffer to add the object topublic void serialize(OutputBuffer buffer, HashMap compression_map)
Array
using a compression map.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |