|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsim.util.DoubleBag
Maintains a simple array (obj) of doubles and the number of doubles (numObjs) in the array (the array can be bigger than this number). You are encouraged to access the doubles directly; they are stored in positions [0 ... numObjs-1]. If you wish to extend the array, you should call the resize method.
DoubleBag is approximately to double what Bag is to Object. However, for obvious reasons, DoubleBag is not a java.util.Collection subclass and is purposely simple (it doesn't have an Iterator for example).
DoubleBag is not synchronized, and so should not be accessed from different threads without locking on it or some appropriate lock double first. DoubleBag also has an unusual, fast method for removing doubles called remove(...), which removes the double simply by swapping the topmost double into its place. This means that after remove(...) is called, the DoubleBag may no longer have the same order (hence the reason it's called a "DoubleBag" rather than some variant on "Vector" or "Array" or "List"). You can guarantee order by calling removeNondestructively(...) instead if you wish, but this is O(n) in the worst case.
Field Summary | |
int |
numObjs
|
double[] |
objs
|
Constructor Summary | |
DoubleBag()
|
|
DoubleBag(DoubleBag other)
Adds the doubles from the other DoubleBag without copying them. |
|
DoubleBag(int capacity)
Creates a DoubleBag with a given initial capacity. |
Method Summary | |
boolean |
add(double obj)
|
boolean |
addAll(DoubleBag other)
|
boolean |
addAll(int index,
double[] other)
|
boolean |
addAll(int index,
DoubleBag other)
|
void |
clear()
|
java.lang.Object |
clone()
|
java.lang.Class |
componentType()
Should return the base component type for this Indexed object, or null if the component type should be queried via getValue(index).getClass.getComponentType() |
boolean |
contains(double o)
|
void |
fill(double o)
Replaces all elements in the bag with the provided object. |
double |
get(int index)
|
java.lang.Object |
getValue(int index)
Throws an IndexOutOfBoundsException if index is inappropriate. |
boolean |
isEmpty()
|
double |
pop()
Returns 0 if the DoubleBag is empty, else removes and returns the topmost double. |
boolean |
push(double obj)
Synonym for add(obj) -- try to use add instead unless you want to think of the DoubleBag as a stack. |
double |
remove(int index)
Removes the double at the given index, moving the topmost double into its position. |
double |
removeNondestructively(int index)
Removes the double at the given index, shifting the other doubles down. |
void |
resize(int toAtLeast)
|
void |
reverse()
Reverses order of the elements in the DoubleBag |
double |
set(int index,
double element)
|
java.lang.Object |
setValue(int index,
java.lang.Object value)
Throws an IndexOutOfBoundsException if index is inappropriate, and IllegalArgumentException if the value is inappropriate. |
void |
shuffle(MersenneTwisterFast random)
Shuffles (randomizes the order of) the DoubleBag |
void |
shuffle(java.util.Random random)
Shuffles (randomizes the order of) the DoubleBag |
int |
size()
|
void |
sort()
Sorts the doubles into ascending numerical order. |
protected void |
throwIndexOutOfBoundsException(int index)
|
double[] |
toArray()
|
double |
top()
Returns 0 if the DoubleBag is empty, else returns the topmost double. |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public double[] objs
public int numObjs
Constructor Detail |
public DoubleBag(int capacity)
public DoubleBag()
public DoubleBag(DoubleBag other)
Method Detail |
public int size()
size
in interface Indexed
public boolean isEmpty()
public boolean addAll(int index, double[] other)
public boolean addAll(DoubleBag other)
public boolean addAll(int index, DoubleBag other)
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
java.lang.CloneNotSupportedException
public void resize(int toAtLeast)
public double top()
public double pop()
public boolean push(double obj)
public boolean add(double obj)
public boolean contains(double o)
public double get(int index)
public java.lang.Object getValue(int index)
Indexed
getValue
in interface Indexed
public double set(int index, double element)
public java.lang.Object setValue(int index, java.lang.Object value)
Indexed
setValue
in interface Indexed
public double removeNondestructively(int index)
public double remove(int index)
public void sort()
public void fill(double o)
public void shuffle(java.util.Random random)
public void shuffle(MersenneTwisterFast random)
public void reverse()
protected void throwIndexOutOfBoundsException(int index)
public void clear()
public double[] toArray()
public java.lang.Class componentType()
Indexed
componentType
in interface Indexed
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |