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
count
Fields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
VectorArray(long count, T[] array, int offset, int stride)
-
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
Appends 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.long
commonPrefixLength(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> 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 firstint
encodeRaw(byte[] bs, int pos)
Writes this Cell's encoding to a byte array, excluding the tag byteint
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 indexint
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 object represents a first class CVM Value.boolean
isPacked()
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<R> R
reduce(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.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.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, toArray
Methods inherited from class convex.core.data.ASequence
add, addAll, assoc, checkRange, contains, containsKey, get, get, remove, set, 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
count, isEmpty, size
Methods 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, write
Methods inherited from class convex.core.data.AObject
attachEncoding, 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
-
Constructor Details
-
VectorArray
-
-
Method Details
-
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 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:AVector
Gets the element at the specified index in this vector -
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:
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:AVector
Gets the VectorLeaf chunk at a given offset -
append
Description copied from class:AVector
Appends a single element to this vector -
isPacked
public boolean isPacked()Description copied from class:AVector
Returns true if this Vector is a single fully packed tree. i.e. a full ListVector or TreeVector. -
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
-
spliterator
- Specified by:
spliterator
in classAVector<T extends ACell>
-
listIterator
Description copied from class:ASequence
Gets the ListIterator for a long position- Specified by:
listIterator
in classAVector<T extends ACell>
- 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
-
isCVMValue
public final boolean isCVMValue()Description copied from class:ACell
Returns 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:
isCVMValue
in classACell
- Returns:
- true if the object is a CVM Value, 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. 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
Description copied from class:ASequence
Gets the sequence of all elements after the first, or null if no elements remain -
assoc
Description copied from class:ASequence
Updates a value at the given position in the sequence. -
longIndexOf
Description copied from class:ASequence
Gets the first long index at which the specified value appears in the the sequence.- 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.- 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
Description copied from class:ASequence
Visits all elements in this sequence, calling the specified consumer for each.- Specified by:
visitElementRefs
in classASequence<T extends ACell>
- Parameters:
f
- Function to call for each element
-
getElementRef
Description copied from class:ASequence
Gets the element Ref at the specified index- Specified by:
getElementRef
in classASequence<T extends ACell>
- Parameters:
index
- Index of element to get- Returns:
- Ref to element at specified index
-
subVector
Description copied from class:ASequence
Gets a vector containing the specified subset of 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- 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
-
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
-
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 -
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. Contained Refs may be either external or embedded.- Specified by:
getRefCount
in classACell
- Returns:
- The number of Refs in this Cell
-
toCanonical
Description copied from class:ACell
Converts this Cell to its canonical version. Returns this if already canonical- Specified by:
toCanonical
in classACell
- Returns:
- Canonical version of Cell
-
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
-