goldman.collection.positional
Class DynamicCircularArray<E>
java.lang.Object
goldman.collection.AbstractCollection<E>
goldman.collection.positional.AbstractPositionalCollection<E>
goldman.collection.positional.Array<E>
goldman.collection.positional.CircularArray<E>
goldman.collection.positional.DynamicCircularArray<E>
- All Implemented Interfaces:
- Collection<E>, PositionalCollection<E>, Iterable<E>
- Direct Known Subclasses:
- TrackedArray
public class DynamicCircularArray<E>
- extends CircularArray<E>
- implements PositionalCollection<E>
This array-based data structure allows element 0 of the positional
collection to be in any slot of the underlying array, with the range of underlying
indices wrapping around as needed, and also performs automatic resizing.
It is best if the size of
the collection is not known a priori and if some insertions and/or
deletions tend to occur near the front portion of the collection.
As with DynamicArray, the application program can provide an initial size in the
constructor and use ensureCapacity
and trimToSize
to optimize performance. This is an untracked implementation.
Method Summary |
protected PositionalCollectionLocator<E> |
addImpl(int p,
Object value)
Inserts object value at position p
and increments the position number for the elements that were at
positions p , ..., size -1. |
void |
ensureCapacity(int capacity)
Increases the capacity of the underlying array if
needed |
void |
removeRange(int fromPos,
int toPos)
Requires 0 ≤ fromPos ≤ toPos < size . |
protected void |
resizeArray(int desiredCapacity)
Changes the capacity of the underlying array
to desiredCapacity while maintaining the same positional collection. |
Methods inherited from class goldman.collection.positional.Array |
add, add, bucketsort, bucketsortImpl, clear, contains, findPosition, get, getCapacity, getLocator, heapsort, heapsort, insertionsort, insertionsort, iterator, iteratorAt, iteratorAtEnd, mergesort, mergesort, positionOf, quicksort, quicksort, radixsort, radixsortImpl, read, remove, remove, removeFirst, removeLast, repositionElementByRank, repositionElementByRank, set, swap, traverseForVisitor, treesort, treesort, trimToSize |
Methods inherited from class goldman.collection.AbstractCollection |
accept, addAll, checkRep, compare, equivalent, getComparator, getElementAtRank, getElementAtRank, getEquivalentElement, getSize, isEmpty, retainAll, toArray, toArray, writeElements |
Methods inherited from interface goldman.collection.positional.PositionalCollection |
add, addFirst, addLast, bucketsort, get, heapsort, heapsort, insertionsort, insertionsort, iterator, iteratorAtEnd, mergesort, mergesort, positionOf, quicksort, quicksort, radixsort, remove, removeFirst, removeLast, repositionElementByRank, repositionElementByRank, set, swap, treesort, treesort |
Methods inherited from interface goldman.collection.Collection |
accept, add, addAll, checkRep, clear, contains, getCapacity, getComparator, getEquivalentElement, getLocator, getSize, isEmpty, remove, retainAll, toArray, toArray, toString, trimToSize |
DynamicCircularArray
public DynamicCircularArray(int capacity,
Comparator<? super E> equivalenceTester)
DynamicCircularArray
public DynamicCircularArray()
DynamicCircularArray
public DynamicCircularArray(int capacity)
resizeArray
protected void resizeArray(int desiredCapacity)
- Description copied from class:
Array
- Changes the capacity of the underlying array
to
desiredCapacity
while maintaining the same positional collection.
- Parameters:
desiredCapacity
- the desired capacity of the underlying array
ensureCapacity
public void ensureCapacity(int capacity)
- Description copied from class:
Array
- Increases the capacity of the underlying array if
needed
- Specified by:
ensureCapacity
in interface Collection<E>
- Overrides:
ensureCapacity
in class Array<E>
- Parameters:
capacity
- the desired capacity
addImpl
protected PositionalCollectionLocator<E> addImpl(int p,
Object value)
- Description copied from class:
Array
- Inserts object
value
at position p
and increments the position number for the elements that were at
positions p
, ..., size
-1.
- Parameters:
p
- a valid user positionvalue
- the object to insert
- Returns:
- null for an untracked implementations
removeRange
public void removeRange(int fromPos,
int toPos)
- Description copied from class:
Array
- Requires 0 ≤
fromPos
≤ toPos
< size
.
It removes the elements at positions
fromPos
, ..., toPos
, inclusive,
from the collection and
decrements the positions of the
elements at positions toPos+1
to size-1
by
toPos-fromPos+1
(the number of elements
being removed).
- Specified by:
removeRange
in interface PositionalCollection<E>
- Overrides:
removeRange
in class Array<E>
- Parameters:
fromPos
- a valid positiontoPos
- a valid position