Package convex.core.data
Class ASequence<T extends ACell>
java.lang.Object
convex.core.data.AObject
convex.core.data.ACell
convex.core.data.ACountable<T>
convex.core.data.ADataStructure<T>
convex.core.data.ACollection<T>
convex.core.data.ASequence<T>
- Type Parameters:
T- Type of list elements
- All Implemented Interfaces:
IAssociative<CVMLong,,T> IValidated,IWriteable,Iterable<T>,Collection<T>,List<T>,SequencedCollection<T>
public abstract class ASequence<T extends ACell>
extends ACollection<T>
implements List<T>, IAssociative<CVMLong,T>
Abstract base class for concrete sequential data structure (immutable persistent lists and vectors etc.)
-
Field Summary
Fields inherited from class convex.core.data.ADataStructure
countFields inherited from class convex.core.data.ACell
cachedRef, memorySize -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidfinal booleanaddAll(int index, Collection<? extends T> c) Updates a value at the given position in the sequence.Associates a key with a value in this associative data structure.protected booleancheckRange(long start, long end) Checks if an index range is valid for this sequenceConcatenates the elements from another sequence to the end of this sequence.Adds an element to the sequence in the natural positionPrepends an element to this sequence, returning a list.booleanbooleancontainsKey(ACell key) Checks if the data structure contains the specified keyempty()Returns an empty instance of the same Type as this data structure.abstract voidget(int index) Gets the element at the specified index in this sequence.abstract Tget(long index) Gets the element at the specified element index in this valueGets the element at the specified keyGet the value associated with a given key.getElementRef(long index) Gets the element Ref at the specified indexfinal booleanSequences are always valid CVM valuesprotected abstract ListIterator<T> listIterator(long l) Gets the ListIterator for a long positionabstract longlongIndexOf(Object value) Gets the first long index at which the specified value appears in the the sequence.abstract longlongLastIndexOf(Object value) Gets the last long index at which the specified value appears in the the sequence.Maps a function over a collection, applying it to each element in turn.next()Gets the sequence of all elements after the first, or null if no elements remain after the first (i.e.final Tremove(int index) reverse()Reverses a sequence, converting Lists to Vectors and vice versaslice(long start, long end) Produces a slice of this sequence, beginning with the specified start index and of the given length.spliterator(long start, long end) Gets a Spliterator for the given range of this sequencesubList(int fromIndex, int toIndex) subVector(long start, long length) Gets a vector containing the specified subset of this sequence, or null if range is invalidACell[]Converts this sequence to a new Cell arrayabstract voidvisitElementRefs(Consumer<Ref<T>> f) Visits all elements in this sequence, calling the specified consumer for each.Methods inherited from class convex.core.data.ACollection
add, addAll, clear, containsAll, copyToArray, encode, getType, iterator, remove, removeAll, retainAll, toArray, toArray, toVectorMethods inherited from class convex.core.data.ADataStructure
checkIndex, conjAll, count, isDataValue, isEmpty, size, toCVMStringMethods inherited from class convex.core.data.ACountable
sliceMethods inherited from class convex.core.data.ACell
attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createEncoding, createRef, encodeRaw, equals, equals, genericEquals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getMemorySize, getRef, getRef, getRefCount, getTag, hashCode, isCanonical, isEmbedded, toCanonical, toString, updateRefs, validate, validateCellMethods inherited from class convex.core.data.AObject
attachEncoding, print, print, printMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface convex.core.data.IWriteable
estimatedEncodingSizeMethods inherited from interface java.util.List
add, addAll, addFirst, addLast, clear, containsAll, equals, getFirst, getLast, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, size, sort, toArray, toArray
-
Constructor Details
-
ASequence
public ASequence(long count)
-
-
Method Details
-
contains
-
longIndexOf
Gets the first long index at which the specified value appears in the the sequence. Similar to Java's standard List.indexOf(...) but supports long indexes.- Parameters:
value- Any value which could appear as an element of the sequence.- Returns:
- Index of the value, or -1 if not found.
-
longLastIndexOf
Gets the last long index at which the specified value appears in the the sequence. Similar to Java's standard List.lastIndexOf(...) but supports long indexes.- Parameters:
value- Any value which could appear as an element of the sequence.- Returns:
- Index of the value, or -1 if not found.
-
map
Description copied from class:ACollectionMaps a function over a collection, applying it to each element in turn.- Specified by:
mapin classACollection<T extends ACell>- Type Parameters:
R- Type of element in resulting collection- Parameters:
mapper- Function to map over collection- Returns:
- Collection after function applied to each element
-
forEach
-
visitElementRefs
-
flatMap
-
concat
Concatenates the elements from another sequence to the end of this sequence. Potentially O(n) in size of resulting sequence- Parameters:
vals- A sequence of values to concatenate.- Returns:
- The concatenated sequence, of the same type as this sequence.
-
addAll
-
next
-
empty
Description copied from class:ADataStructureReturns an empty instance of the same Type as this data structure.- Specified by:
emptyin classADataStructure<T extends ACell>- Returns:
- An empty data structure
-
get
-
isCVMValue
public final boolean isCVMValue()Sequences are always valid CVM values- Specified by:
isCVMValuein classACell- Returns:
- true if the object is a CVM Value, false otherwise
-
get
Description copied from class:ACountableGets the element at the specified element index in this value- Specified by:
getin classACountable<T extends ACell>- Parameters:
index- Index of element to get- Returns:
- Element at the specified index
-
get
-
get
Description copied from class:ADataStructureGet the value associated with a given key.- Specified by:
getin classADataStructure<T extends ACell>- Parameters:
key- Key to look up in data structurenotFound- Value to return if key is not found- Returns:
- Value from collection, or notFound value if not found
-
containsKey
Description copied from class:ADataStructureChecks if the data structure contains the specified key- Specified by:
containsKeyin classADataStructure<T extends ACell>- Parameters:
key- Associative key to look up- Returns:
- true if the data structure contains the key, false otherwise
-
getElementRef
Gets the element Ref at the specified index- Specified by:
getElementRefin classACountable<T extends ACell>- Parameters:
index- Index of element to get- Returns:
- Ref to element at specified index
-
set
-
assoc
Description copied from class:ADataStructureAssociates a key with a value in this associative data structure. May return null if the Key or Value is incompatible with the data structure.- Specified by:
associn classADataStructure<T extends ACell>- Parameters:
key- Associative keyvalue- Value to associate with key- Returns:
- Updates data structure, or null if data types are invalid
-
assoc
-
checkRange
protected boolean checkRange(long start, long end) Checks if an index range is valid for this sequence- Parameters:
start-length-
-
add
-
remove
-
toCellArray
Converts this sequence to a new Cell array- Overrides:
toCellArrayin classACollection<T extends ACell>- Returns:
- A new cell array containing the elements of this sequence
-
conj
-
slice
Produces a slice of this sequence, beginning with the specified start index and of the given length. The start and end must be contained within this sequence. Will return the same sequence if the start is zero and the length matches this sequence.- Specified by:
slicein classACountable<T extends ACell>- Parameters:
start- Index of the start elementend- End index(exclusive)- Returns:
- A sequence representing the requested slice.
-
cons
-
subVector
-
subList
-
listIterator
Gets the ListIterator for a long position- Parameters:
l-- Returns:
- ListIterator instance.
-
spliterator
- Specified by:
spliteratorin interfaceCollection<T extends ACell>- Specified by:
spliteratorin interfaceIterable<T extends ACell>- Specified by:
spliteratorin interfaceList<T extends ACell>
-
spliterator
Gets a Spliterator for the given range of this sequence- Parameters:
start- Start position (inclusive)end- End position (exclusive)- Returns:
- Spliterator instance
-
reverse
-