Class FixedStack<N>
java.lang.Object
com.conversantmedia.util.collection.FixedStack<N>
- All Implemented Interfaces:
Stack<N>
A very high performance stack to replace java.util.Stack. This
stack wraps around rather than checking for bounds.
The java version of Stack is based on Vector and completely outdated.
The performance of java.util.Stack is poor at best.
This version is a small fast fixed size stack. There
is no bounds checking so it should only be used when the stack size is known
in advance.
This object is not thread safe.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()clear the stackbooleanLinear search the stack for contains - not an efficient operationbooleanisEmpty()peek()peek at the top of the stackpop()pop the next element off the stackbooleanadd an element to the stackinthow much available space in the stackintsize()Return the size of the stack
-
Field Details
-
size
private final int size -
mask
private final int mask -
stack
-
stackTop
private int stackTop
-
-
Constructor Details
-
FixedStack
public FixedStack(int size) construct a new stack of given capacity- Parameters:
size- - the stack size
-
-
Method Details
-
push
-
contains
-
peek
-
pop
-
size
-
remainingCapacity
public int remainingCapacity()how much available space in the stack- Specified by:
remainingCapacityin interfaceStack<N>- Returns:
- int - the number of empty slots available in the stack
-
isEmpty
-
clear
-