Package org.htmlunit.cyberneko.util
Class MiniStack<E>
java.lang.Object
org.htmlunit.cyberneko.util.MiniStack<E>
Extremely light stack implementation. Perfect for inlining.
- Since:
- 3.10.0
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Empties the stack.boolean
isEmpty()
Checks if we have any element at all on the stack.peek()
Returns the top/last element without removing it.pop()
Removes and returns the last elementvoid
Add a new element on top of the stack.void
reset()
Resets the stack to zero but does not clean it.int
size()
Returns the current size of the stack.
-
Field Details
-
elements_
-
pos_
private int pos_
-
-
Constructor Details
-
MiniStack
public MiniStack()Create a new empty stack with 8 elements capacity.A reference are typically (less than 32 GB memory) 4 bytes. The overhead of any object is about 24 bytes, give or take, hence 8*4 + 24 fits a cache line of 64 bytes.
-
-
Method Details
-
clear
public void clear()Empties the stack. It will not only reset the pointer but empty out the backing array to ensure we are not holding old references. -
reset
public void reset()Resets the stack to zero but does not clean it. Use with caution to avoid holding old objects and preventing them from GC. -
pop
Removes and returns the last element- Returns:
- the last element or null of none
-
peek
Returns the top/last element without removing it. Will return null if we don't have a last element.- Returns:
- the top/last element if any, null otherwise
-
push
Add a new element on top of the stack. You can add null but the return value of pop and peek will become ambiguous.- Parameters:
element
- the element to add
-
isEmpty
public boolean isEmpty()Checks if we have any element at all on the stack.- Returns:
- true if the stack holds elements, false otherwise
-
size
public int size()Returns the current size of the stack.- Returns:
- the size of the stack, always >= 0
-