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
ConstructorsConstructorDescriptionSnapshotSeq(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()voidend()Releases the guarantee that the array returned bybegin()won't be modified.voidpop()Removes and returns the last item.remove(int index) Removes and returns the item at the specified index.booleanRemoves the first instance of the specified value in the array.booleanRemoves from this array all of elements contained in the specified array.voidremoveRange(int start, int end) Removes the items between the specified indices, inclusive.reverse()voidT[]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.voidswap(int first, int second) voidtruncate(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, find, first, firstOpt, flatMap, flatten, get, getFrac, groupBy, groupByCount, hashCode, indexOf, indexOf, indexOf, isEmpty, iterator, lastIndexOf, list, map, mapFloat, mapInt, mapInt, max, max, max, min, 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, toArray, toString, toString, toString, with, with, withArraysMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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:SeqRemoves the first instance of the specified value in the array. -
remove
Description copied from class:SeqRemoves and returns the item at the specified index. -
removeRange
public void removeRange(int start, int end) Description copied from class:SeqRemoves the items between the specified indices, inclusive.- Overrides:
removeRangein classSeq<T>
-
removeAll
Description copied from class:SeqRemoves from this array all of elements contained in the specified array. -
pop
Description copied from class:SeqRemoves and returns the last item. -
clear
-
sort
Description copied from class:SeqSorts this array. The array elements must implementComparable. This method is not thread safe (usesSort.instance()). -
sort
Description copied from class:SeqSorts the array. This method is not thread safe (usesSort.instance()). -
reverse
-
shuffle
-
truncate
public void truncate(int newSize) Description copied from class:SeqReduces 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:SeqSets the array size, leaving any values beyond the current size null.
-