Package convex.core.data
Class ADataStructure<E extends ACell>
java.lang.Object
convex.core.data.AObject
convex.core.data.ACell
convex.core.data.ACountable<E>
convex.core.data.ADataStructure<E>
- Type Parameters:
E
- Type of Data Structure elements
- All Implemented Interfaces:
IValidated
,IWriteable
- Direct Known Subclasses:
ACollection
,AMap
Abstract base class for Persistent data structures. Each can be regarded as a
countable, immutable collection of elements.
Data structures in general support:
- Immutability
- Addition of an element(s) of appropriate type
- Construction of an empty (zero) element
"When you know your data can never change out from underneath you, everything is different." - Rich Hickey
-
Field Summary
FieldsFields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract ADataStructure<E>
Associates a key with a value in this associative data structure.abstract <R extends ACell>
ADataStructure<R>conj
(R x) Adds an element to this data structure, in the natural manner defined by the general data structure type.<R extends ACell>
ADataStructure<R>conjAll
(ACollection<R> xs) Adds multiple elements to this data structure, in the natural manner defined by the general data structure type.abstract boolean
containsKey
(ACell key) Checks if the data structure contains the specified keyfinal long
count()
Gets the count of elements in this data structureabstract ADataStructure<E>
empty()
Returns an empty instance of the same Type as this data structure.abstract ACell
Get the value associated with a given key.abstract ACell
Get the value associated with a given key.final boolean
isEmpty()
Checks if this data structure is empty, i.e.final int
size()
Gets the size of this data structure as an int.toCVMString
(long limit) Converts CVM data structure to a CVM String, as per 'print'Methods inherited from class convex.core.data.ACountable
get, getElementRef, slice, slice
Methods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, encode, encodeRaw, equals, equals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, getRef, getRefCount, getTag, getType, hashCode, isCanonical, isCompletelyEncoded, isCVMValue, isEmbedded, mark, mark, toCanonical, toString, updateRefs, validate, validateCell, write
Methods inherited from class convex.core.data.AObject
attachEncoding, print, print, print
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface convex.core.data.IWriteable
estimatedEncodingSize
-
Field Details
-
count
protected final long count
-
-
Constructor Details
-
ADataStructure
protected ADataStructure(long count)
-
-
Method Details
-
count
public final long count()Gets the count of elements in this data structure- Specified by:
count
in classACountable<E extends ACell>
- Returns:
- Number of elements in this collection.
-
size
public final int size()Description copied from class:ACountable
Gets the size of this data structure as an int. Returns Integer.MAX_SIZE if the count is larger than can fit in an int. If this might be a problem, use count() instead.- Overrides:
size
in classACountable<E extends ACell>
- Returns:
- Number of elements in this collection.
-
empty
Returns an empty instance of the same Type as this data structure.- Specified by:
empty
in classACountable<E extends ACell>
- Returns:
- An empty data structure
-
isEmpty
public final boolean isEmpty()Description copied from class:ACountable
Checks if this data structure is empty, i.e. has a count of zero elements.- Overrides:
isEmpty
in classACountable<E extends ACell>
- Returns:
- true if this data structure is empty, false otherwise
-
conj
Adds an element to this data structure, in the natural manner defined by the general data structure type. e.g. append at the end of a vector.- Type Parameters:
R
- Type of Value added- Parameters:
x
- New element to add- Returns:
- The updated data structure, or null if a failure occurred due to invalid element type
-
conjAll
Adds multiple elements to this data structure, in the natural manner defined by the general data structure type. e.g. append at the end of a vector. This may be more efficient than using 'conj' for individual items.- Type Parameters:
R
- Type of Value added- Parameters:
xs
- New elements to add- Returns:
- The updated data structure, or null if a failure occurred due to invalid elementtypes
-
assoc
Associates a key with a value in this associative data structure. May return null if the Key or Value is incompatible with the data structure.- Parameters:
key
- Associative keyvalue
- Value to associate with key- Returns:
- Updates data structure, or null if data types are invalid
-
get
Get the value associated with a given key.- Parameters:
key
- Associative key to look up- Returns:
- Value from collection, or a falsey value (null or false) if not found
-
get
Get the value associated with a given key.- Parameters:
key
- Key to look up in data structurenotFound
- Value to return if key is not found- Returns:
- Value from collection, or notFound value if not found
-
containsKey
Checks if the data structure contains the specified key- Parameters:
key
- Associative key to look up- Returns:
- true if the data structure contains the key, false otherwise
-
toCVMString
Converts CVM data structure to a CVM String, as per 'print'- Overrides:
toCVMString
in classACell
- Parameters:
limit
- Limit of CVM String length in UTF-8 bytes- Returns:
- CVM String, or null if limit exceeded
-