|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectstatalign.base.CircularArray<E>
E
- element typepublic class CircularArray<E>
Dynamically growing circular array with extremely efficient deque and hash operations. Can be used as a dynamically growing hash (with semi-contiguous key range for space-efficiency), deque (queue or stack), array, perhaps in turns. Offers amortised O(1) time for each implemented operation. Does not shrink.
Constructor Summary | |
---|---|
CircularArray()
Constructs an empty CircularArray with an initial capacity of MIN_CAPACITY. |
|
CircularArray(int initialCapacity)
Constructs an empty CircularArray with a given minimal initial capacity but at least MIN_CAPACITY. |
Method Summary | |
---|---|
E |
get(int key)
Retrieves the element at the given key in the array or null if there is no element with that key. |
int |
length()
Difference between the highest and lowest key of elements in the array plus 1. |
E |
pop()
Retrieves the last element in the array (element with key endKey-1) and decreases endKey. |
void |
push(E elem)
Adds new element at the end of the array (key endKey is assigned), growing the array if full, then endKey is increased. |
void |
put(int key,
E element)
Puts a new (key,element) pair into the CircularArray, growing the array if the new key range doesn't fit into the array. |
E |
shift()
Retrieves the first element in the array (element with key startKey) and increases startKey. |
E[] |
toArray(E[] newData)
Copies contents of this CircularArray to a regular array. |
void |
unshift(E elem)
Adds new element at the beginning of the array (key startKey-1 is assigned), growing the array if full, then startKey is decreased. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CircularArray()
public CircularArray(int initialCapacity)
initialCapacity
- minimum capacity of the new arrayMethod Detail |
---|
public int length()
public void put(int key, E element)
key
- key of the elementelement
- the element to store at the given keypublic E get(int key)
key
- the given key
public void push(E elem)
elem
- the element to be addedpublic E pop()
public void unshift(E elem)
elem
- the element to be addedpublic E shift()
public E[] toArray(E[] newData)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |