Package convex.core.data
Class VectorArray<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>
convex.core.data.AVector<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>
Experimental: implementation of AVector backed by a Java array for temporary usage purposes.
-
Field Summary
Fields inherited from class convex.core.data.ADataStructure
countFields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedVectorArray(long count, T[] array, int offset, int stride) -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanAppends a single element to this vectorappendChunk(VectorLeaf<T> chunkVector)Appends a ListVector chunk to this vector.assoc(long i, R value)Updates a value at the given position in the sequence.longcommonPrefixLength(AVector<T> b)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> voidcopyToArray(R[] arr, int offset)Copies the elements of this collection in order to an array at the specified offsetintencode(byte[] bs, int pos)Writes this Cell's encoding to a byte array, including a tag byte which will be written firstintencodeRaw(byte[] bs, int pos)Writes this Cell's encoding to a byte array, excluding the tag byteintEstimate the encoded data size for this Cell.voidget(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 indexintGets the number of Refs contained within this Cell.booleanReturns true if this vector is in canonical format, i.e.booleanReturns true if this object represents a first class CVM Value.booleanisPacked()Returns true if this Vector is a single fully packed tree.listIterator(long index)Gets the ListIterator for a long positionlonglongIndexOf(Object value)Gets the first long index at which the specified value appears in the the sequence.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<R> Rreduce(BiFunction<? super R,? super T,? extends R> func, R value)spliterator(long position)<R extends ACell>
VectorArray<R>subVector(long start, long length)Gets a vector containing the specified subset of this sequence.Converts this Cell to its canonical version.toVector()Converts this collection to a canonical vector of elementsupdateRefs(IRefFunction func)Updates all Refs in this object using the given function.voidValidates the local structure and invariants of this cell.voidvisitElementRefs(Consumer<Ref<T>> f)Visits all elements in this sequence, calling the specified consumer for each.Methods inherited from class convex.core.data.AVector
appendAll, conj, conjAll, cons, empty, flatMap, get, getTag, getType, indexOf, iterator, lastIndexOf, listIterator, mergeWith, print, reverse, slice, spliterator, toArrayMethods inherited from class convex.core.data.ASequence
add, addAll, assoc, checkRange, contains, containsKey, get, get, remove, set, subList, toCellArrayMethods inherited from class convex.core.data.ACollection
add, addAll, clear, containsAll, remove, removeAll, retainAll, toArrayMethods inherited from class convex.core.data.ADataStructure
count, isEmpty, sizeMethods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, equals, equals, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, getRef, hashCode, isEmbedded, toString, validate, writeMethods inherited from class convex.core.data.AObject
attachEncoding, printMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Constructor Details
-
VectorArray
-
-
Method Details
-
listIterator
-
estimatedEncodingSize
public int estimatedEncodingSize()Description copied from interface:IWriteableEstimate the encoded data size for this Cell. Used for quickly sizing buffers. Implementations should try to return a size that is likely to contain the entire object when represented in binary format, including the tag byte.- Returns:
- The estimated size for the binary representation of this object.
-
get
Description copied from class:AVectorGets the element at the specified index in this vector -
appendChunk
Description copied from class:AVectorAppends a ListVector chunk to this vector. This vector must contain a whole number of chunks- Specified by:
appendChunkin classAVector<T extends ACell>- Parameters:
chunkVector- A chunk to append. Must be a ListVector of maximum size- Returns:
- The updated vector, of the same type as this vector @
-
getChunk
Description copied from class:AVectorGets the VectorLeaf chunk at a given offset -
append
Description copied from class:AVectorAppends a single element to this vector -
isPacked
public boolean isPacked()Description copied from class:AVectorReturns true if this Vector is a single fully packed tree. i.e. a full ListVector or TreeVector. -
anyMatch
-
allMatch
-
map
Description copied from class:ACollectionMaps a function over a collection, applying it to each element in turn. -
concat
Description copied from class:ASequenceConcatenates the elements from another sequence to the end of this sequence. Potentially O(n) in size of resulting sequence -
reduce
-
spliterator
- Specified by:
spliteratorin classAVector<T extends ACell>
-
listIterator
Description copied from class:ASequenceGets the ListIterator for a long position- Specified by:
listIteratorin classAVector<T extends ACell>- Returns:
- ListIterator instance.
-
isCanonical
public boolean isCanonical()Description copied from class:AVectorReturns true if this vector is in canonical format, i.e. suitable as top-level serialised representation of a vector.- Specified by:
isCanonicalin classAVector<T extends ACell>- Returns:
- true if the vector is in canonical format, false otherwise
-
isCVMValue
public final boolean isCVMValue()Description copied from class:ACellReturns true if this object represents a first class CVM Value. Sub-structural cells that are not themselves first class values should return false. CVM values might not be in a canonical format, e.g. temporary data structures- Specified by:
isCVMValuein classACell- Returns:
- true if the object is a CVM Value, false otherwise
-
updateRefs
Description copied from class:ACellUpdates 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. 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:
updateRefsin classAVector<T extends ACell>- Parameters:
func- Ref update function- Returns:
- Cell with updated Refs
-
commonPrefixLength
Description copied from class:AVectorComputes the length of the longest common prefix of this vector and another vector.- Specified by:
commonPrefixLengthin classAVector<T extends ACell>- Parameters:
b- Any vector- Returns:
- Length of the longest common prefix
-
next
Description copied from class:ASequenceGets the sequence of all elements after the first, or null if no elements remain -
assoc
Description copied from class:ASequenceUpdates a value at the given position in the sequence. -
longIndexOf
Description copied from class:ASequenceGets the first long index at which the specified value appears in the the sequence.- Specified by:
longIndexOfin 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:ASequenceGets the last long index at which the specified value appears in the the sequence.- Specified by:
longLastIndexOfin 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
Description copied from class:ASequenceVisits all elements in this sequence, calling the specified consumer for each.- Specified by:
visitElementRefsin classASequence<T extends ACell>- Parameters:
f- Function to call for each element
-
getElementRef
Description copied from class:ASequenceGets the element Ref at the specified index- Specified by:
getElementRefin classASequence<T extends ACell>- Parameters:
index- Index of element to get- Returns:
- Ref to element at specified index
-
subVector
Description copied from class:ASequenceGets a vector containing the specified subset of this sequence. -
encode
public int encode(byte[] bs, int pos)Description copied from class:ACellWrites this Cell's encoding to a byte array, including a tag byte which will be written first- Specified by:
encodein interfaceIWriteable- Specified by:
encodein 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:ACollectionConverts this collection to a canonical vector of elements- Specified by:
toVectorin classACollection<T extends ACell>- Returns:
- This collection coerced to a vector
-
validateCell
Description copied from class:ACellValidates 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:
validateCellin classACell- Throws:
InvalidDataException- If the Cell is invalid
-
encodeRaw
public int encodeRaw(byte[] bs, int pos)Description copied from class:ACellWrites this Cell's encoding to a byte array, excluding the tag byte -
getRefCount
public int getRefCount()Description copied from class:ACellGets the number of Refs contained within this Cell. This number is final / immutable for any given instance. Contained Refs may be either external or embedded.- Specified by:
getRefCountin classACell- Returns:
- The number of Refs in this Cell
-
toCanonical
Description copied from class:ACellConverts this Cell to its canonical version. Returns this if already canonical- Specified by:
toCanonicalin classACell- Returns:
- Canonical version of Cell
-
copyToArray
protected <R> void copyToArray(R[] arr, int offset)Description copied from class:ACollectionCopies the elements of this collection in order to an array at the specified offset- Specified by:
copyToArrayin classACollection<T extends ACell>- Type Parameters:
R- Type of array elements required
-