Package convex.core.data
Class RefDirect<T extends ACell>
java.lang.Object
convex.core.data.AObject
convex.core.data.Ref<T>
convex.core.data.RefDirect<T>
- Type Parameters:
T- Type of Value referenced
- All Implemented Interfaces:
IValidated,IWriteable,Comparable<Ref<T>>
Ref subclass for direct in-memory references.
Direct Refs store the underlying value directly with a regular Java strong reference.
Care must be taken to ensure recursive structures do not exceed reasonable memory bounds. In smart contract execution, juice limits serve this purpose.
-
Field Summary
Fields inherited from class convex.core.data.Ref
ANNOUNCED, BAD_MASK, EMBEDDING_MASK, FALSE_VALUE, flags, hash, INDIRECT_ENCODING_LENGTH, INTERNAL, INTERNAL_FLAGS, INVALID, KNOWN_EMBEDDED_MASK, MAX_STATUS, NON_EMBEDDED_MASK, NULL_VALUE, PERSISTED, STATUS_MASK, STORED, TRUE_VALUE, UNKNOWN, VALIDATED, VERIFICATION_MASK, VERIFIED_MASK -
Method Summary
Modifier and TypeMethodDescriptioncreate(T value)Creates a new Direct ref to the given value.Creates a direct Ref to the given valueConstruction function for a Direct RefbooleanequalsValue(Ref<T> a)Checks if two Ref Values are equal.intEstimate the encoded data size for this Cell.getHash()Gets the Hash of this ref's value.getValue()Gets the value from this Ref.booleanisDirect()Return true if this Ref is a direct reference, i.e.booleanChecks if this Ref refers to missing data, i.e.toDirect()Converts this Ref to a RefDirectvoidvalidate()Validates the complete structure of this object.withFlags(int newFlags)Create a new Ref of the same type with updated flagsUpdates the value stored within this Ref.Methods inherited from class convex.core.data.Ref
accumulateRefSet, addAllToSet, cachedHash, compareTo, createArray, createEncoding, encode, equals, findMissing, flagsWithStatus, forHash, get, get, getEncodingLength, getFlags, getMemorySize, getStatus, hashCode, isEmbedded, isPersisted, markEmbedded, mergeFlags, persist, persist, persistShallow, persistShallow, print, readRaw, setFlags, toString, updateRefs, withMinimumStatus, writeMethods inherited from class convex.core.data.AObject
attachEncoding, getEncoding, print
-
Method Details
-
create
Construction function for a Direct Ref- Type Parameters:
T- Type of value- Parameters:
value- Value for the Refhash- Hash (may be null)status- Status for the Ref- Returns:
- New Direct Ref
-
create
Creates a direct Ref to the given value- Type Parameters:
T- Type of value- Parameters:
value- Any value (may be embedded or otherwise, but should not be null)hash- Hash of value's encoding, or null if not known- Returns:
- Direct Ref to Value
-
create
Creates a new Direct ref to the given value. Does not compute hash.- Type Parameters:
T- Type of Value- Parameters:
value- Value- Returns:
- Direct Ref to Value
-
getValue
Description copied from class:RefGets the value from this Ref. Important notes: - May throw a MissingDataException if the data does not exist in available storage - Will return null if and only if the Ref refers to the null value -
isDirect
public boolean isDirect()Description copied from class:RefReturn true if this Ref is a direct reference, i.e. the value is pinned in memory and cannot be garbage collected -
getHash
Description copied from class:RefGets the Hash of this ref's value. -
toDirect
Description copied from class:RefConverts this Ref to a RefDirect -
equalsValue
Description copied from class:RefChecks if two Ref Values are equal. Equality is defined as referring to the same data, i.e. have an identical hash.- Specified by:
equalsValuein classRef<T extends ACell>- Parameters:
a- The Ref to compare with- Returns:
- true if Refs have the same value, false otherwise
-
validate
Description copied from interface:IValidatedValidates the complete structure of this object. It is necessary to ensure all child Refs are validated, so the general contract for validate is:- Call super.validate() - which will indirectly call validateCell()
- Call validate() on any contained cells in this class
- Specified by:
validatein interfaceIValidated- Overrides:
validatein classRef<T extends ACell>- Throws:
InvalidDataException- If the data Valie is invalid in any way
-
withValue
Description copied from class:RefUpdates the value stored within this Ref. New value must be equal in value to the old value (identical hash), but may have updated internal refs etc. -
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.
-
isMissing
public boolean isMissing()Description copied from class:RefChecks if this Ref refers to missing data, i.e. a Cell that does not exist in the currect store. -
withFlags
Description copied from class:RefCreate a new Ref of the same type with updated flags
-