|
mjc | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.multijava.util.IntStack
This class represents a simple stack of integer values. Unlike java.util.Stack it is not synchronized and instead of storing Objects it store int value. Both of these changes make it faster than using Stack.
| Field Summary | |
static int |
DEFAULT_CAPACITY
|
static float |
MIN_LOAD_FACTOR
|
private int |
minimumCapacity
|
private int |
shrinkIfTopLessThanThis
|
private int[] |
storage
|
private int |
top
|
| Constructor Summary | |
IntStack()
Constructs a stack with default initial capacity. |
|
IntStack(int initialCapacity)
Constructs a stack with the given initial capacity. |
|
| Method Summary | |
private void |
adjustCapacity(int newCapacity)
Create new storage array of size newCapacity. |
int |
capacity()
Returns the capacity of the stack (i.e., the total number of items that the stack can contains without automatically allocating more storage space. |
boolean |
isEmpty()
Returns true if this stack is empty. |
private void |
maybeExpandStorage()
Expand the storage to accomodate more items. |
private void |
maybeShrinkStorage()
Shrink the storage to release memory if the load factor of the storage falls below MIN_LOAD_FACTOR. |
int |
peek()
Returns the top item in the stack without modifying the stack. |
int |
pop()
Pops the top item from the stack and returns it. |
void |
push(int i)
Pushes the given item onto the stack. |
int |
size()
Returns the size of this stack (i.e., the total number of items in the stack. |
private void |
throwExceptionIfEmpty()
Throws an empty stack exception is the stack is empty. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
private int[] storage
private int top
private int minimumCapacity
private int shrinkIfTopLessThanThis
public static final int DEFAULT_CAPACITY
public static final float MIN_LOAD_FACTOR
| Constructor Detail |
public IntStack()
public IntStack(int initialCapacity)
| Method Detail |
public boolean isEmpty()
public int peek()
EmptyStackException - if the stack is emptypublic int pop()
EmptyStackException - if the stack is emptypublic void push(int i)
public int size()
public int capacity()
private void throwExceptionIfEmpty()
private void maybeShrinkStorage()
private void maybeExpandStorage()
assignable storage, shrinkIfTopLessThanThis; ensures size() < capacity();
private void adjustCapacity(int newCapacity)
requires newCapacity >= size() + 1; requires newCapacity >= minimumCapacity; assignable storage, shrinkIfTopLessThanThis; ensures storage.length == newCapacity;
|
mjc | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||