Package convex.core.data
Class VectorArray<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>
convex.core.data.AVector<T>
convex.core.data.ASpecialVector<T>
convex.core.data.VectorArray<T>
- Type Parameters:
T
- Type of vector elements
- All Implemented Interfaces:
IAssociative<CVMLong,
,T> IValidated
,IWriteable
,Iterable<T>
,Collection<T>
,List<T>
,SequencedCollection<T>
Non-canonical vector implementation designed to make operations on small temporary vectors more efficient.
Directly wraps an array of cells, considered effectively immutable
-
Field Summary
Fields inherited from class convex.core.data.ADataStructure
count
Fields inherited from class convex.core.data.ACell
cachedRef, memorySize
-
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
Appends a single element to this vectorappendChunk
(AVector<T> listVector) Appends a ListVector chunk to this vector.Updates a value at the given position in the sequence.long
Computes the length of the longest common prefix of this vector and another vector.Concatenates the elements from another sequence to the end of this sequence.protected <R> void
copyToArray
(R[] arr, int offset) Copies the elements of this collection in order to an array at the specified offsetint
encode
(byte[] bs, int pos) Writes this Cell's encoding to a byte array, including a tag byte which will be written first.int
encodeRaw
(byte[] bs, int pos) Writes this Cell's encoding to a byte array, excluding the tag byte.boolean
int
Estimate the encoded data size for this Cell.void
get
(long i) Gets the element at the specified index in this vectorgetChunk
(long offset) Gets the VectorLeaf chunk at a given offsetgetElementRef
(long index) Gets the element Ref at the specified indexgetElementRefUnsafe
(long i) Gets an element Ref from this vector, assuming bounds already checkedgetRef
(int i) Gets a numbered child Ref from within this Cell.int
Gets the number of Refs contained within this Cell.boolean
Returns true if this vector is in canonical format, i.e.boolean
Returns true if this Vector is a single fully packed tree.listIterator
(long index) Gets the ListIterator for a long positionlong
longIndexOf
(Object value) Gets the first long index at which the specified value appears in the the sequence.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 remain after the first (i.e.static <T extends ACell>
VectorArray<T> <R> R
reduce
(BiFunction<? super R, ? super T, ? extends R> func, R value) slice
(long start, long end) Produces a slice of this sequence, beginning with the specified start index and of the given length.protected ACell
Converts this Cell to a canonical version.toVector()
Converts this collection to a canonical vector of elementsupdateRefs
(IRefFunction func) Updates all Refs in this object using the given function.void
Validates the local structure and invariants of this cell.void
visitElementRefs
(Consumer<Ref<T>> f) Visits all elements in this sequence, calling the specified consumer for each.static <T extends ACell>
VectorArray<T> Methods inherited from class convex.core.data.AVector
appendAll, conj, conjAll, cons, empty, equals, flatMap, get, getTag, getType, indexOf, isPacked, iterator, lastIndexOf, listIterator, mergeWith, print, reverse, subVector, toArray
Methods inherited from class convex.core.data.ASequence
add, addAll, assoc, checkRange, contains, containsKey, get, get, isCVMValue, remove, set, spliterator, spliterator, subList, toCellArray
Methods inherited from class convex.core.data.ACollection
add, addAll, clear, containsAll, remove, removeAll, retainAll, toArray
Methods inherited from class convex.core.data.ADataStructure
checkIndex, count, isDataValue, isEmpty, size, toCVMString
Methods inherited from class convex.core.data.ACountable
slice
Methods inherited from class convex.core.data.ACell
attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createEncoding, createRef, equals, genericEquals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getMemorySize, getRef, hashCode, isEmbedded, toString, validate
Methods inherited from class convex.core.data.AObject
attachEncoding, 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
-
Method Details
-
wrap
-
of
-
listIterator
-
estimatedEncodingSize
public int estimatedEncodingSize()Description copied from interface:IWriteable
Estimate the encoded data size for this Cell. Used for quickly sizing buffers. Implementations should try to return a size that is highly likely to contain the entire object when encoded, including the tag byte. Should not traverse soft Refs, i.e. must be usable on arbitrary partial data structures- Returns:
- The estimated size for the binary representation of this object.
-
get
-
appendChunk
Description copied from class:AVector
Appends a ListVector chunk to this vector. This vector must contain a whole number of chunks- Specified by:
appendChunk
in classAVector<T extends ACell>
- Parameters:
listVector
- A chunk to append. Must be a ListVector of maximum size- Returns:
- The updated vector, of the same type as this vector @
-
getChunk
-
append
-
isFullyPacked
public boolean isFullyPacked()Description copied from class:AVector
Returns true if this Vector is a single fully packed tree. i.e. a full ListVector or TreeVector.- Specified by:
isFullyPacked
in classAVector<T extends ACell>
- Returns:
- true if fully packed, false otherwise
-
anyMatch
-
allMatch
-
map
Description copied from class:ACollection
Maps a function over a collection, applying it to each element in turn. -
concat
Description copied from class:ASequence
Concatenates the elements from another sequence to the end of this sequence. Potentially O(n) in size of resulting sequence -
reduce
-
listIterator
Description copied from class:ASequence
Gets the ListIterator for a long position- Specified by:
listIterator
in classAVector<T extends ACell>
- Parameters:
index
-- Returns:
- ListIterator instance.
-
isCanonical
public boolean isCanonical()Description copied from class:AVector
Returns true if this vector is in canonical format, i.e. suitable as top-level serialised representation of a vector.- Specified by:
isCanonical
in classAVector<T extends ACell>
- Returns:
- true if the vector is in canonical format, false otherwise
-
updateRefs
Description copied from class:ACell
Updates all Refs in this object using the given function. The function *must not* change the hash value of Refs, in order to ensure structural integrity of modified data structures. The implementation *should* re-attach any original encoding in order to prevent re-encoding or surplus hashing This is a building block for a very sneaky trick that enables use to do a lot of efficient operations on large trees of smart references. Must return the same object if no Refs are altered.- Specified by:
updateRefs
in classAVector<T extends ACell>
- Parameters:
func
- Ref update function- Returns:
- Cell with updated Refs
-
commonPrefixLength
Description copied from class:AVector
Computes the length of the longest common prefix of this vector and another vector.- Specified by:
commonPrefixLength
in classAVector<T extends ACell>
- Parameters:
b
- Any vector- Returns:
- Length of the longest common prefix
-
next
-
assoc
Description copied from class:ASequence
Updates a value at the given position in the sequence. -
encodeRaw
public int encodeRaw(byte[] bs, int pos) Description copied from class:ACell
Writes this Cell's encoding to a byte array, excluding the tag byte. -
getElementRefUnsafe
-
longIndexOf
Description copied from class:ASequence
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.- Specified by:
longIndexOf
in classASequence<T extends ACell>
- Parameters:
value
- Any value which could appear as an element of the sequence.- Returns:
- Index of the value, or -1 if not found.
-
longLastIndexOf
Description copied from class:ASequence
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.- Specified by:
longLastIndexOf
in classASequence<T extends ACell>
- Parameters:
value
- Any value which could appear as an element of the sequence.- Returns:
- Index of the value, or -1 if not found.
-
forEach
-
visitElementRefs
-
getElementRef
-
slice
Description copied from class:ASequence
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. -
encode
public int encode(byte[] bs, int pos) Description copied from class:ACell
Writes this Cell's encoding to a byte array, including a tag byte which will be written first. Cell must be canonical, or else an error may occur.- Specified by:
encode
in interfaceIWriteable
- Specified by:
encode
in classACollection<T extends ACell>
- Parameters:
bs
- A byte array to which to write the encodingpos
- The offset into the byte array- Returns:
- New position after writing
-
toVector
Description copied from class:ACollection
Converts this collection to a canonical vector of elements- Specified by:
toVector
in classACollection<T extends ACell>
- Returns:
- This collection coerced to a vector
-
copyToArray
protected <R> void copyToArray(R[] arr, int offset) Description copied from class:ACollection
Copies the elements of this collection in order to an array at the specified offset- Specified by:
copyToArray
in classACollection<T extends ACell>
- Type Parameters:
R
- Type of array elements required- Parameters:
arr
-offset
-
-
validateCell
Description copied from class:ACell
Validates the local structure and invariants of this cell. Called by validate() super implementation. Should validate directly contained data, but should not validate all other structure of this cell. In particular, should not traverse potentially missing child Refs.- Specified by:
validateCell
in classACell
- Throws:
InvalidDataException
- If the Cell is invalid
-
equals
-
toCanonical
Description copied from class:ACell
Converts this Cell to a canonical version. Must return this Cell if already canonical, may be O(n) in size of value otherwise. Callers should usually use getCanonical(), which caches canonical instances once created- Specified by:
toCanonical
in classACell
- Returns:
- Canonical version of Cell
-
getRefCount
public int getRefCount()Description copied from class:ACell
Gets the number of Refs contained within this Cell. This number is final / immutable for any given instance and is defined by the Cell encoding rules. Contained Refs may be either external or embedded.- Overrides:
getRefCount
in classACell
- Returns:
- The number of Refs in this Cell
-
getRef
-