Maintains a simple array (objs) 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.

Resizes the objs array to max(numObjs, desiredLength), unless that value is greater than or equal to objs.length,
in which case no resizing is done (this operation only shrinks -- use resize() instead).

numObjs

Constructor Detail

DoubleBag

DoubleBag

DoubleBag

Adds the doubles from the other DoubleBag without copying them. The size of the
new DoubleBag is the minimum necessary size to hold the doubles. If the Other DoubleBag is
null, a new empty DoubleBag is created.

DoubleBag

public DoubleBag(double[] other)

Creates a DoubleBag with the given elements. If the Other array is
null, a new empty DoubleBag is created.

clone

resize

public void resize(int toAtLeast)

shrink

public void shrink(int desiredLength)

Resizes the objs array to max(numObjs, desiredLength), unless that value is greater than or equal to objs.length,
in which case no resizing is done (this operation only shrinks -- use resize() instead).
This is an O(n) operation, so use it sparingly.

top

public double top()

Returns 0 if the DoubleBag is empty, else returns the topmost double.

pop

public double pop()

Returns 0 if the DoubleBag is empty, else removes and returns the topmost double.

push

public boolean push(double obj)

Synonym for add(obj) -- try to use add instead unless you
want to think of the DoubleBag as a stack.