Package convex.core.data
Class ASymbolic
- All Implemented Interfaces:
IValidated
,IWriteable
,Comparable<ABlobLike<?>>
Abstract based class for symbolic objects (Keywords, Symbols)
-
Field Summary
FieldsFields inherited from class convex.core.data.ACell
cachedRef, memorySize
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte
byteAt
(long i) Gets the byte at the specified position.protected long
Calculates the Memory Size for this Cell.long
count()
Returns the number of elements in this valueCreates a new Ref for this Cellempty()
Returns a canonical, singleton empty instance of the same type as this Countable value.boolean
equalsBytes
(ABlob b) Compare the byte content of this BlobLike to a Blob valuefinal int
Estimate the encoded data size for this Cell.get
(long index) Gets the element at the specified element index in this valueint
getBytes
(byte[] dest, int destOffset) Copies the bytes from this instance to a given destination arraygetElementRef
(long index) Gets a Ref to the element at the specified element index in this collectionfinal StringShort
getName()
Gets the name of this symbolic valuegetRef
(int i) Gets a numbered child Ref from within this Cell.int
Gets the number of Refs contained within this Cell.final int
hashCode()
Gets the Java hashCode for this cell.long
Returns the number of matching hex digits in the given hex range of another Blob.final boolean
Returns true if this cell is a first class CVM Value allowable in the CVM state Sub-structural cells that are not themselves first class values should return false Records and types that are not permissible on the CVM should return false.final boolean
Returns true if this cell instance is a first class value, i.e.boolean
Determines if this Cell Represents an embedded object.long
Converts this BlobLike to the corresponding long value.slice
(long start, long end) Gets a slice of this data structuretoBlob()
Convert this BlobLike object to an ABlob instance, in the most efficient way.updateRefs
(IRefFunction func) Updates all Refs in this object using the given function.abstract void
Validates this Symbolic valueprotected static boolean
validateName
(AString name) Methods inherited from class convex.core.data.ABlobLike
appendHex, byteAtUnchecked, compareTo, getBytes, getHexDigit, hexEquals, hexLength, hexMatch, toFlatBlob, toHexString, toHexString
Methods inherited from class convex.core.data.ACountable
isEmpty, size, slice
Methods inherited from class convex.core.data.ACell
attachMemorySize, attachRef, cachedEncoding, cachedHash, createEncoding, encode, encodeRaw, equals, equals, genericEquals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getMemorySize, getRef, getTag, getType, isCanonical, toCanonical, toCVMString, toString, validate
Methods inherited from class convex.core.data.AObject
attachEncoding, print, print, print
-
Field Details
-
name
-
-
Constructor Details
-
ASymbolic
-
-
Method Details
-
createRef
-
isCVMValue
public final boolean isCVMValue()Description copied from class:ACell
Returns true if this cell is a first class CVM Value allowable in the CVM state Sub-structural cells that are not themselves first class values should return false Records and types that are not permissible on the CVM should return false. Pretty much everything else should return true. Note: 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
-
isDataValue
public final boolean isDataValue()Description copied from class:ACell
Returns true if this cell instance is a first class value, i.e. not a component of a larger data structure Sub-structural cells that are not themselves first class values should return false Everything else should return true.- Overrides:
isDataValue
in classABlobLike<CVMChar>
- Returns:
- true if the object is a Value, false otherwise
-
calcMemorySize
protected long calcMemorySize()Description copied from class:ACell
Calculates the Memory Size for this Cell. Assumes not already calculated Requires any child Refs to be either direct or of persisted in store at minimum, or you might get a MissingDataException- Overrides:
calcMemorySize
in classACell
- Returns:
- Memory Size of this Cell
-
estimatedEncodingSize
public final 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.
-
getName
Gets the name of this symbolic value- Returns:
- Name as a short CVM String
-
validateName
-
isEmbedded
public boolean isEmbedded()Description copied from class:ACell
Determines if this Cell Represents an embedded object. Embedded objects are encoded directly into the encoding of the containing Cell (avoiding the need for a hashed reference). Subclasses should override this if they have a cheap O(1) way to determine if they are embedded or otherwise.- Overrides:
isEmbedded
in classACell
- Returns:
- true if Cell is embedded, false otherwise
-
hashCode
public final int hashCode()Description copied from class:ACell
Gets the Java hashCode for this cell. Must be consistent with equals. Default is the hashCode of the Encoding blob, since this is consistent with encoding-based equality. However, different Types may provide more efficient hashcodes provided that the usual invariants are preserved -
validateCell
Validates this Symbolic value- Specified by:
validateCell
in classACell
- Throws:
InvalidDataException
- If the symbolic value is invalid
-
byteAt
-
hexMatch
Description copied from class:ABlobLike
Returns the number of matching hex digits in the given hex range of another Blob. Assumes range is valid for both blobs. Returns length if this Blob is exactly equal to the specified hex range. -
empty
-
getBytes
public int getBytes(byte[] dest, int destOffset) Description copied from class:ABlobLike
Copies the bytes from this instance to a given destination array -
longValue
public long longValue()Description copied from class:ABlobLike
Converts this BlobLike to the corresponding long value. Assumes big-endian format, as if the entire blob is interpreted as an unsigned big integer. Higher bytes outside the Long range will be ignored, i.e. the lowest 64 bits are taken -
toBlob
-
equalsBytes
Description copied from class:ABlobLike
Compare the byte content of this BlobLike to a Blob value- Specified by:
equalsBytes
in classABlobLike<CVMChar>
- Parameters:
b
- Blob value to compare with- Returns:
- `true` if byte contents are exactly equal, `false` otherwise
-
count
public long count()Description copied from class:ACountable
Returns the number of elements in this value- Specified by:
count
in classACountable<CVMChar>
- Returns:
- Number of elements
-
getElementRef
Description copied from class:ACountable
Gets a Ref to the element at the specified element index in this collection- Overrides:
getElementRef
in classABlobLike<CVMChar>
- Parameters:
index
- Index of element to get- Returns:
- Element at the specified index
-
get
Description copied from class:ACountable
Gets the element at the specified element index in this value- Specified by:
get
in classACountable<CVMChar>
- Parameters:
index
- Index of element to get- Returns:
- Element at the specified index
-
slice
Description copied from class:ACountable
Gets a slice of this data structure- Specified by:
slice
in classACountable<CVMChar>
- Parameters:
start
- Start index (inclusive)end
- end index (exclusive)- Returns:
- Slice of data structure, or null if invalid slice
-
getRef
Description copied from class:ACell
Gets a numbered child Ref from within this Cell. WARNING: May need to convert to a canonical instance -
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.- Overrides:
updateRefs
in classACell
- Parameters:
func
- Ref update function- Returns:
- Cell with updated Refs
-
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
-