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