Package convex.core.lang.impl
Class MultiFn<T extends ACell>
java.lang.Object
convex.core.data.AObject
convex.core.data.ACell
convex.core.lang.AFn<T>
convex.core.lang.impl.AClosure<T>
convex.core.lang.impl.MultiFn<T>
- All Implemented Interfaces:
IValidated
,IWriteable
,IFn<T>
-
Field Summary
Fields inherited from class convex.core.lang.impl.AClosure
lexicalEnv
Fields inherited from class convex.core.data.ACell
cachedRef, memorySize
-
Method Summary
Modifier and TypeMethodDescriptionint
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.int
Estimate the encoded data size for this Cell.getRef
(int i) Gets a numbered child Ref from within this Cell.int
Gets the number of Refs contained within this Cell.boolean
hasArity
(int n) Tests if this function supports the given arity.Invoke this function in the given context.boolean
Returns true if this Cell is in a canonical representation.boolean
print
(BlobBuilder bb, long limit) Prints this Object to a readable String Representation.boolean
printInternal
(BlobBuilder bb, long limit) Print the "internal" representation of a closure e.g.Decodes a MultiFn instance from a Blob encodingConverts this Cell to a canonical version.updateRefs
(IRefFunction func) Updates all Refs in this object using the given function.void
Validates the local structure and invariants of this cell.withEnvironment
(AVector<ACell> env) Produces an copy of this closure with the specified environmentMethods inherited from class convex.core.lang.AFn
equals, getTag, getType, isCVMValue, isDataValue, supportsArgs
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, toCVMString, toString, validate
Methods inherited from class convex.core.data.AObject
attachEncoding, print, print
-
Method Details
-
create
-
isCanonical
public boolean isCanonical()Description copied from class:ACell
Returns true if this Cell is in a canonical representation. Non-canonical objects may be used on a temporary internal basis, they should be converted to canonical representations for general purpose use.- Specified by:
isCanonical
in classACell
- Returns:
- true if the object is in canonical format, false otherwise
-
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
-
print
Description copied from class:AObject
Prints this Object to a readable String Representation. SECURITY: Must halt and return false in O(1) time when limit of printing is exceeded otherwise DoS attacks may be possible. -
printInternal
Description copied from class:AClosure
Print the "internal" representation of a closure e.g. "[x] 1", excluding the 'fn' symbol.- Specified by:
printInternal
in classAClosure<T extends ACell>
- Parameters:
bb
- StringBuilder to print tolimit
- Limit of BlobBuilder size- Returns:
- True if printed successfully within limit, false otherwise
-
invoke
Description copied from interface:IFn
Invoke this function in the given context. -
hasArity
-
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 classAFn<T extends ACell>
- Parameters:
func
- Ref update function- Returns:
- Cell with updated Refs
-
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
-
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 classACell
- Parameters:
bs
- A byte array to which to write the encodingpos
- The offset into the byte array- Returns:
- New position after writing
-
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. -
read
Decodes a MultiFn instance from a Blob encoding- Parameters:
b
- Blob to read frompos
- Start position in Blob (location of tag byte)- Returns:
- New decoded instance
- Throws:
BadFormatException
- In the event of any encoding error
-
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.
-
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
Description copied from class:ACell
Gets a numbered child Ref from within this Cell. WARNING: May need to convert to a canonical instance -
withEnvironment
Description copied from class:AClosure
Produces an copy of this closure with the specified environment- Specified by:
withEnvironment
in classAClosure<T extends ACell>
- Parameters:
env
- New lexical environment to use for this closure- Returns:
- Closure updated with new lexical environment
-