Package convex.core.data
Class ASequence<T extends ACell>
java.lang.Object
convex.core.data.AObject
convex.core.data.ACell
convex.core.data.ACountable<E>
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>
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
count
Fields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal void
final boolean
addAll
(int index, Collection<? extends T> c) assoc
(long i, R value) Updates a value at the given position in the sequence.Associates a key with a value in this associative data structure.protected void
checkRange
(long start, long length) Checks if an index range is valid for this sequenceConcatenates the elements from another sequence to the end of this sequence.conj
(R value) Adds an element to the sequence in the natural positionPrepends an element to this sequence, returning a list.boolean
boolean
containsKey
(ACell key) Checks if the data structure contains the specified keyabstract void
get
(int index) Gets the element at the specified index in this sequence.abstract T
get
(long index) Gets the element at the specified element index in this collectionGets the element at the specified keyGet the value associated with a given key.getElementRef
(long index) Gets the element Ref at the specified indexprotected abstract ListIterator<T>
listIterator
(long l) Gets the ListIterator for a long positionabstract long
longIndexOf
(Object value) Gets the first long index at which the specified value appears in the the sequence.abstract long
longLastIndexOf
(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 remainfinal T
remove
(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.ACell[]
Converts this sequence to a new Cell arrayabstract void
visitElementRefs
(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, toVector
Methods inherited from class convex.core.data.ADataStructure
checkIndex, conjAll, count, empty, isEmpty, size, toCVMString
Methods inherited from class convex.core.data.ACountable
slice
Methods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, encodeRaw, equals, equals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, getRef, getRefCount, getTag, hashCode, isCanonical, isCompletelyEncoded, isCVMValue, isEmbedded, mark, mark, toCanonical, toString, updateRefs, validate, validateCell
Methods inherited from class convex.core.data.AObject
attachEncoding, print, print, print
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface convex.core.data.IWriteable
estimatedEncodingSize
Methods inherited from interface java.util.List
add, addAll, clear, containsAll, equals, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeAll, replaceAll, retainAll, 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:ACollection
Maps a function over a collection, applying it to each element in turn.- Specified by:
map
in 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
Visits all elements in this sequence, calling the specified consumer for each.- Parameters:
f
- Function to call for each element
-
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
Gets the sequence of all elements after the first, or null if no elements remain- Returns:
- Sequence following the first element
-
get
Gets the element at the specified index in this sequence. Behaves as if the index was considered as a long -
get
Description copied from class:ACountable
Gets the element at the specified element index in this collection- Specified by:
get
in classACountable<T extends ACell>
- Parameters:
index
- Index of element to get- Returns:
- Element at the specified index
-
get
Gets the element at the specified key- Specified by:
get
in classADataStructure<T extends ACell>
- Parameters:
key
- Key of element to get- Returns:
- The value at the specified index, or null if not valid
-
get
Description copied from class:ADataStructure
Get the value associated with a given key.- Specified by:
get
in 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:ADataStructure
Checks if the data structure contains the specified key- Specified by:
containsKey
in 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:
getElementRef
in classACountable<T extends ACell>
- Parameters:
index
- Index of element to get- Returns:
- Ref to element at specified index
-
set
-
assoc
Description copied from class:ADataStructure
Associates 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:
assoc
in 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
Updates a value at the given position in the sequence.- Parameters:
i
- Index of element to updatevalue
- New element value- Returns:
- Updated sequence, or null if index is out of range
-
checkRange
protected void checkRange(long start, long length) 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:
toCellArray
in classACollection<T extends ACell>
- Returns:
- A new cell array containing the elements of this sequence
-
conj
Adds an element to the sequence in the natural position- Specified by:
conj
in classACollection<T extends ACell>
- Type Parameters:
R
- Type of Value added- Parameters:
value
- Value to add- Returns:
- Updated sequence
-
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:
slice
in classACountable<T extends ACell>
- Parameters:
start
- Index of the start elementend
- End index(exclusive)- Returns:
- A sequence representing the requested slice.
-
cons
Prepends an element to this sequence, returning a list.- Parameters:
x
- Any new element value- Returns:
- A list starting with the new element.
-
subVector
Gets a vector containing the specified subset of this sequence.- Parameters:
start
- Start index of sub vectorlength
- Length of sub vector to produce- Returns:
- Sub-vector of this sequence
-
subList
-
listIterator
Gets the ListIterator for a long position- Parameters:
l
-- Returns:
- ListIterator instance.
-
spliterator
- Specified by:
spliterator
in interfaceCollection<T extends ACell>
- Specified by:
spliterator
in interfaceIterable<T extends ACell>
- Specified by:
spliterator
in 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
Reverses a sequence, converting Lists to Vectors and vice versa- Returns:
- Reversed sequence
-