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, memorySize
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract ADataStructure
<E> Associates a key with a value in this associative data structure.final void
checkIndex
(long ix) Checks if the given index is in range for this data structureabstract ADataStructure
<E> Adds an element to this data structure, in the natural manner defined by the general data structure type.conjAll
(ACollection<? extends E> 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.boolean
Returns true if this cell instance is a first class value, i.e.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
attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createEncoding, createRef, encode, encodeRaw, equals, equals, genericEquals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getMemorySize, getRef, getRef, getRefCount, getTag, getType, hashCode, isCanonical, isCVMValue, isEmbedded, toCanonical, toString, updateRefs, validate, validateCell
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
-
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
-
isDataValue
public 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.- Specified by:
isDataValue
in classACell
- Returns:
- true if the object is a Value, 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.- 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.- Parameters:
xs
- New elements to add- Returns:
- The updated data structure, or null if a failure occurred due to invalid element types
-
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
-
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
-
checkIndex
public final void checkIndex(long ix) Checks if the given index is in range for this data structure- Parameters:
ix
- Index to check- Throws:
IndexOutOfBoundsException
- if index is invalid
-