- class
ArraySeq
(T): SeqCollection!(T), Sortable!(T);
- Dynamically allocated and resized Arrays.
Beyond implementing its interfaces, adds methods
to adjust capacities. The default heuristics for resizing
usually work fine, but you can adjust them manually when
you need to.
ArraySeqs are generally like java.util.Vectors. But unlike them,
ArraySeqs do not actually allocate arrays when they are constructed.
Among other consequences, you can adjust the capacity `for free'
after construction but before adding elements. You can adjust
it at other times as well, but this may lead to more expensive
resizing. Also, unlike Vectors, they release their internal arrays
whenever they are empty.
author:
Doug Lea
@version 0.93
For an introduction to this package see Overview .
- int
minCapacity
;
- The minimum capacity of any non-empty buffer
- T[]
array
;
- The elements, or null if no buffer yet allocated.
- this();
- Make a new empty ArraySeq.
- this(Predicate screener);
- Make an empty ArraySeq with given element screener
- this(Predicate s, T[] b, int c);
- Special version of constructor needed by clone()
- ArraySeq!(T)
duplicate
();
- Make an independent copy. The elements themselves are not cloned
- int
capacity
();
- return the current internal buffer
capacity
(zero if no buffer allocated).
Returns:
capacity
(always greater than or equal to size())
- void
capacity
(int newCap);
- Set the internal buffer
capacity
to max(size(), newCap).
That is, if given an argument less than the current
number of elements, the
capacity
is just set to the
current number of elements. Thus, elements are never lost
by setting the
capacity
.
@param newCap the desired
capacity
.
Returns:
condition:
capacity
() >= size() &&
version() != PREV(this).version() == (
capacity
() != PREV(this).
capacity
())
- bool
contains
(T element);
- Implements tango.util.collection.impl.Collection.Collection.
contains
Time complexity: O(n).
See Also:
tango.util.collection.impl.Collection.Collection.
contains
- uint
instances
(T element);
- Implements tango.util.collection.impl.Collection.Collection.
instances
Time complexity: O(n).
See Also:
tango.util.collection.impl.Collection.Collection.
instances
- GuardIterator!(T)
elements
();
- Implements tango.util.collection.impl.Collection.Collection.
elements
Time complexity: O(1).
See Also:
tango.util.collection.impl.Collection.Collection.
elements
- int
opApply
(int delegate(ref T value) dg);
- Implements tango.util.collection.model.View.View.
opApply
Time complexity: O(n).
See Also:
tango.util.collection.model.View.View.
opApply
- T
head
();
- Implements tango.util.collection.model.Seq.Seq.
head
.
Time complexity: O(1).
See Also:
tango.util.collection.model.Seq.Seq.
head
- T
tail
();
- Implements tango.util.collection.model.Seq.Seq.
tail
.
Time complexity: O(1).
See Also:
tango.util.collection.model.Seq.Seq.
tail
- T
get
(int index);
- Implements tango.util.collection.model.Seq.Seq.
get
.
Time complexity: O(1).
See Also:
tango.util.collection.model.Seq.Seq.
get
- int
first
(T element, int startingIndex = 0);
- Implements tango.util.collection.model.Seq.Seq.
first
.
Time complexity: O(n).
See Also:
tango.util.collection.model.Seq.Seq.
first
- int
last
(T element, int startingIndex = 0);
- Implements tango.util.collection.model.Seq.Seq.
last
.
Time complexity: O(n).
See Also:
tango.util.collection.model.Seq.Seq.
last
- ArraySeq
subset
(int from, int _length);
- Implements tango.util.collection.model.Seq.Seq.subseq.
Time complexity: O(length).
See Also:
tango.util.collection.model.Seq.Seq.subseq
- void
clear
();
- Implements tango.util.collection.impl.Collection.Collection.
clear
.
Time complexity: O(1).
See Also:
tango.util.collection.impl.Collection.Collection.
clear
- void
remove
(T element);
- Implements tango.util.collection.impl.Collection.Collection.removeOneOf.
Time complexity: O(n).
See Also:
tango.util.collection.impl.Collection.Collection.removeOneOf
- void
replace
(T oldElement, T newElement);
- Implements tango.util.collection.impl.Collection.Collection.replaceOneOf
Time complexity: O(n).
See Also:
tango.util.collection.impl.Collection.Collection.replaceOneOf
- void
replaceAll
(T oldElement, T newElement);
- Implements tango.util.collection.impl.Collection.Collection.replaceAllOf.
Time complexity: O(n * number of replacements).
See Also:
tango.util.collection.impl.Collection.Collection.replaceAllOf
- void
removeAll
(T element);
- Implements tango.util.collection.impl.Collection.Collection.exclude.
Time complexity: O(n * instances(element)).
See Also:
tango.util.collection.impl.Collection.Collection.exclude
- T
take
();
- Implements tango.util.collection.impl.Collection.Collection.
take
.
Time complexity: O(1).
Takes the rightmost element of the array.
See Also:
tango.util.collection.impl.Collection.Collection.
take
- void
sort
(Comparator!(T) cmp);
- Implements tango.util.collection.SortableCollection.
sort
.
Time complexity: O(n log n).
Uses a quicksort-based algorithm.
See Also:
tango.util.collection.SortableCollection.
sort
- void
prepend
(T element);
- Implements tango.util.collection.impl.SeqCollection.SeqCollection.
prepend
.
Time complexity: O(n)
See Also:
tango.util.collection.impl.SeqCollection.SeqCollection.
prepend
- void
replaceHead
(T element);
- Implements tango.util.collection.impl.SeqCollection.SeqCollection.
replaceHead
.
Time complexity: O(1).
See Also:
tango.util.collection.impl.SeqCollection.SeqCollection.
replaceHead
- void
removeHead
();
- Implements tango.util.collection.impl.SeqCollection.SeqCollection.
removeHead
.
Time complexity: O(n).
See Also:
tango.util.collection.impl.SeqCollection.SeqCollection.
removeHead
- void
append
(T element);
- Implements tango.util.collection.impl.SeqCollection.SeqCollection.
append
.
Time complexity: normally O(1), but O(n) if size() == capacity().
See Also:
tango.util.collection.impl.SeqCollection.SeqCollection.
append
- void
replaceTail
(T element);
- Implements tango.util.collection.impl.SeqCollection.SeqCollection.
replaceTail
.
Time complexity: O(1).
See Also:
tango.util.collection.impl.SeqCollection.SeqCollection.
replaceTail
- void
removeTail
();
- Implements tango.util.collection.impl.SeqCollection.SeqCollection.
removeTail
.
Time complexity: O(1).
See Also:
tango.util.collection.impl.SeqCollection.SeqCollection.
removeTail
- void
addAt
(int index, T element);
- Implements tango.util.collection.impl.SeqCollection.SeqCollection.
addAt
.
Time complexity: O(n).
See Also:
tango.util.collection.impl.SeqCollection.SeqCollection.
addAt
- void
removeAt
(int index);
- Implements tango.util.collection.impl.SeqCollection.SeqCollection.remove.
Time complexity: O(n).
See Also:
tango.util.collection.impl.SeqCollection.SeqCollection.
removeAt
- void
replaceAt
(int index, T element);
- Implements tango.util.collection.impl.SeqCollection.SeqCollection.
replaceAt
.
Time complexity: O(1).
See Also:
tango.util.collection.impl.SeqCollection.SeqCollection.
replaceAt
- void
prepend
(Iterator!(T) e);
- Implements tango.util.collection.impl.SeqCollection.SeqCollection.
prepend
.
Time complexity: O(n + number of elements in e) if (e
instanceof CollectionIterator) else O(n * number of elements in e)
See Also:
tango.util.collection.impl.SeqCollection.SeqCollection.
prepend
- void
append
(Iterator!(T) e);
- Implements tango.util.collection.impl.SeqCollection.SeqCollection.
append
.
Time complexity: O(number of elements in e)
See Also:
tango.util.collection.impl.SeqCollection.SeqCollection.
append
- void
addAt
(int index, Iterator!(T) e);
- Implements tango.util.collection.impl.SeqCollection.SeqCollection.
addAt
.
Time complexity: O(n + number of elements in e) if (e
instanceof CollectionIterator) else O(n * number of elements in e)
See Also:
tango.util.collection.impl.SeqCollection.SeqCollection.
addAt
- void
removeRange
(int fromIndex, int toIndex);
- Implements tango.util.collection.impl.SeqCollection.SeqCollection.removeFromTo.
Time complexity: O(n).
See Also:
tango.util.collection.impl.SeqCollection.SeqCollection.removeFromTo
- void
quickSort
(T[] s, int lo, int hi, Comparator!(T) cmp);
- An implementation of Quicksort using medians of 3 for partitions.
Used internally by sort.
It is public and static so it can be used to sort plain
arrays as well.
@param s, the array to sort
@param lo, the least index to sort from
@param hi, the greatest index
@param cmp, the comparator to use for comparing elements
- T[]
toArray
();
- expose collection content as an array
- void
growBy_
(int inc);
- Main method to control buffer sizing.
The heuristic used for growth is:
if out of space:
if need less than minCapacity, grow to minCapacity
else grow by average of requested size and minCapacity.
For small buffers, this causes them to be about 1/2 full.
while for large buffers, it causes them to be about 2/3 full.
For shrinkage, the only thing we do is unlink the buffer if it is empty.
@param inc, the amount of space to grow by. Negative values mean shrink.
Returns:
condition:
adjust record of count, and if any of
the above conditions apply, allocate and copy into a new
buffer of the appropriate size.
- void
insert_
(int index, Iterator!(T) e);
- Utility to splice in enumerations
- void
checkImplementation
();
- Implements tango.util.collection.model.View.View.
checkImplementation
.
See Also:
tango.util.collection.model.View.View.
checkImplementation
- template
ArrayIterator
(T)
- opApply() has migrated here to mitigate the virtual call
on method get()
|