Package arc.struct
Class SnapshotSeq<T>
java.lang.Object
arc.struct.Seq<T>
arc.struct.SnapshotSeq<T>
Guarantees that array entries provided by
begin()
between indexes 0 and Seq.size
at the time begin was called
will not be modified until end()
is called. If modification of the SnapshotArray occurs between begin/end, the backing
array is copied prior to the modification, ensuring that the backing array that was returned by begin()
is unaffected.
To avoid allocation, an attempt is made to reuse any extra array created as a result of this copy on subsequent copies.
It is suggested iteration be done in this specific way:
SnapshotArray array = new SnapshotArray(); // ... Object[] items = array.begin(); for (int i = 0, n = array.size; i < n; i++) { Object item = items[i]; // ... } array.end();
-
Nested Class Summary
Nested classes/interfaces inherited from class arc.struct.Seq
Seq.SeqIterable<T>
-
Field Summary
Fields inherited from class arc.struct.Seq
items, iteratorsAllocated, ordered, size
-
Constructor Summary
ConstructorDescriptionSnapshotSeq
(boolean ordered, int capacity) SnapshotSeq
(boolean ordered, int capacity, Class<?> arrayType) SnapshotSeq
(boolean ordered, T[] array, int startIndex, int count) SnapshotSeq
(int capacity) SnapshotSeq
(Seq<T> array) SnapshotSeq
(Class<?> arrayType) SnapshotSeq
(T[] array) -
Method Summary
Modifier and TypeMethodDescriptionT[]
begin()
Returns the backing array, which is guaranteed to not be modified beforeend()
.clear()
void
end()
Releases the guarantee that the array returned bybegin()
won't be modified.void
pop()
Removes and returns the last item.remove
(int index) Removes and returns the item at the specified index.boolean
Removes the first instance of the specified value in the array.boolean
Removes from this array all of elements contained in the specified array.void
removeRange
(int start, int end) Removes the items between the specified indices, inclusive.reverse()
void
T[]
setSize
(int newSize) Sets the array size, leaving any values beyond the current size null.shuffle()
sort()
Sorts this array.sort
(Comparator<? super T> comparator) Sorts the array.void
swap
(int first, int second) void
truncate
(int newSize) Reduces the size of the array to the specified size.static <T> SnapshotSeq<T>
with
(T... array) Methods inherited from class arc.struct.Seq
add, add, add, add, add, add, addAll, addAll, addAll, addAll, addAll, addUnique, allMatch, any, as, asMap, asMap, asSet, contains, contains, contains, containsAll, containsAll, copy, count, distinct, each, each, ensureCapacity, equals, filter, find, first, firstOpt, flatMap, flatten, get, getFrac, hashCode, indexOf, indexOf, indexOf, isEmpty, iterator, lastIndexOf, list, map, mapFloat, mapInt, max, max, min, min, min, peek, pop, random, random, random, reduce, remove, remove, removeAll, removeAll, replace, replace, resize, retainAll, select, select, selectFrom, selectRanked, selectRankedIndex, set, set, shrink, sort, sortComparing, sum, sumf, toArray, toArray, toString, toString, toString, with, with, withArrays
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
SnapshotSeq
public SnapshotSeq() -
SnapshotSeq
-
SnapshotSeq
-
SnapshotSeq
public SnapshotSeq(boolean ordered, int capacity) -
SnapshotSeq
-
SnapshotSeq
-
SnapshotSeq
public SnapshotSeq(int capacity) -
SnapshotSeq
-
-
Method Details
-
with
- See Also:
-
begin
Returns the backing array, which is guaranteed to not be modified beforeend()
. -
end
public void end()Releases the guarantee that the array returned bybegin()
won't be modified. -
set
-
insert
-
swap
public void swap(int first, int second) -
remove
Description copied from class:Seq
Removes the first instance of the specified value in the array. -
remove
Description copied from class:Seq
Removes and returns the item at the specified index. -
removeRange
public void removeRange(int start, int end) Description copied from class:Seq
Removes the items between the specified indices, inclusive.- Overrides:
removeRange
in classSeq<T>
-
removeAll
Description copied from class:Seq
Removes from this array all of elements contained in the specified array. -
pop
Description copied from class:Seq
Removes and returns the last item. -
clear
-
sort
Description copied from class:Seq
Sorts this array. The array elements must implementComparable
. This method is not thread safe (usesSort.instance()
). -
sort
Description copied from class:Seq
Sorts the array. This method is not thread safe (usesSort.instance()
). -
reverse
-
shuffle
-
truncate
public void truncate(int newSize) Description copied from class:Seq
Reduces the size of the array to the specified size. If the array is already smaller than the specified size, no action is taken. -
setSize
Description copied from class:Seq
Sets the array size, leaving any values beyond the current size null.
-