Package convex.core.data
Class Index<K extends ABlobLike<?>,V extends ACell>
java.lang.Object
convex.core.data.AObject
convex.core.data.ACell
convex.core.data.ACountable<MapEntry<K,V>>
convex.core.data.ADataStructure<MapEntry<K,V>>
convex.core.data.AMap<K,V>
convex.core.data.AIndex<K,V>
convex.core.data.Index<K,V>
- Type Parameters:
K
- Type of KeysV
- Type of values
- All Implemented Interfaces:
IAssociative<K,
,V> IValidated
,IWriteable
,Map<K,
V>
Index node implementation, providing an efficient radix tree based immutable data structure for indexed access and sorting.
Supporting:
- An optional prefix string
- An optional entry with this exact prefix
- Up to 16 child entries at the next level of depth
-
Nested Class Summary
-
Field Summary
FieldsFields inherited from class convex.core.data.ADataStructure
count
Fields inherited from class convex.core.data.ACell
cachedRef, memorySize
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
accumulateEntrySet
(Set<Map.Entry<K, V>> h) Accumulate all entries from this map in the given mutable Set.protected void
accumulateKeySet
(Set<K> h) Accumulate all keys from this map in the given mutable Set.protected void
accumulateValues
(List<V> al) Accumulate all values from this map in the given mutable list.Associates a blob key with a value in this data structure.assocEntry
(MapEntry<K, V> e) Associate the given map entry into the map.boolean
containsValue
(ACell value) CHecks if this map contains the given value.create
(K k, V v) empty()
Returns an empty instance of the same Type as this data structure.int
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.entryAt
(long ix) Gets the entry in this map at a specified index, according to the map-specific order.boolean
Checks for equality with another Cell.boolean
Checks this Index for equality with another Indexint
Estimate the encoded data size for this Cell.filterValues
(Predicate<V> pred) Filters all values in this map with the given predicate.void
forEach
(BiConsumer<? super K, ? super V> action) Gets the map entry for a given BlobgetEntryByHash
(Hash hash) Gets the map entry with the specified hashgetRef
(int i) Gets a numbered child Ref from within this Cell.int
Gets the number of Refs contained within this Cell.byte
getTag()
Gets the tag byte for this cell.boolean
Returns true if this Cell is in a canonical representation.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.boolean
Returns true if this cell instance is a first class value, i.e.static <K extends ABlobLike<?>>
booleankeyMatch
(K a, K b) Tests if two keys match (up to the maximum index key depth)none()
<R> R
reduceEntries
(BiFunction<? super R, MapEntry<K, V>, ? extends R> func, R initial) Reduce over all map entries in this map<R> R
reduceValues
(BiFunction<? super R, ? super V, ? extends R> func, R initial) Reduce over all values in this mapslice
(long start) Slices this Index, starting at the specified position Removes n leading entries from this Index, in key order.slice
(long start, long end) Returns a slice of this IndexConverts this Cell to a canonical version.unsafeCreate
(long depth, MapEntry<K, V> entry, Ref<Index>[] entries, int mask, long count) updateRefs
(IRefFunction func) Updates all Refs in this object using the given function.void
validate()
Validates the complete structure of this object.void
Validates the local structure and invariants of this cell.Methods inherited from class convex.core.data.AIndex
containsKey, dissoc, entrySet, get, getEntry, getKeyRefEntry, getType
Methods inherited from class convex.core.data.AMap
clear, conj, containsKey, containsKeyRef, containsValue, entryVector, get, get, get, getElementRef, getKeys, keySet, merge, print, put, putAll, remove, values
Methods inherited from class convex.core.data.ADataStructure
checkIndex, conjAll, count, isEmpty, size, toCVMString
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, toString
Methods inherited from class convex.core.data.AObject
attachEncoding, print, print
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, getOrDefault, hashCode, isEmpty, merge, putIfAbsent, remove, replace, replace, replaceAll, size
-
Field Details
-
EMPTY_CHILDREN
-
EMPTY
Empty Index singleton
-
-
Constructor Details
-
Index
-
-
Method Details
-
unsafeCreate
-
create
-
create
-
of
-
of
-
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. -
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 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 classADataStructure<MapEntry<K extends ABlobLike<?>,
V extends ACell>> - Returns:
- true if the object is a Value, false otherwise
-
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
-
get
-
getEntry
-
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. -
getRef
Description copied from class:ACell
Gets a numbered child Ref from within this Cell. WARNING: May need to convert to a canonical instance -
assoc
Description copied from class:AIndex
Associates a blob key with a value in this data structure. Returns null if the key is not a valid Index key -
dissoc
-
keyMatch
Tests if two keys match (up to the maximum index key depth)- Parameters:
a
- First keyb
- second key- Returns:
- True if keys match
-
accumulateEntrySet
-
accumulateKeySet
-
accumulateValues
-
forEach
-
assocEntry
Description copied from class:AMap
Associate the given map entry into the map. May return null if the map entry is not valid for this map type. -
reduceValues
Description copied from class:AMap
Reduce over all values in this map -
reduceEntries
Description copied from class:AMap
Reduce over all map entries in this map -
filterValues
Description copied from class:AMap
Filters all values in this map with the given predicate. -
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. -
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- Specified by:
estimatedEncodingSize
in interfaceIWriteable
- Specified by:
estimatedEncodingSize
in classAIndex<K extends ABlobLike<?>,
V extends ACell> - Returns:
- The estimated size for the binary representation of this object.
-
read
public static <K extends ABlobLike<?>,V extends ACell> Index<K,V> read(Blob b, int pos) throws BadFormatException - Throws:
BadFormatException
-
getEntryByHash
Description copied from class:AMap
Gets the map entry with the specified hash -
validate
Description copied from interface:IValidated
Validates 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:
validate
in interfaceIValidated
- Overrides:
validate
in classACell
- Throws:
InvalidDataException
- If the data Value is invalid in any way
-
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
-
empty
-
none
-
entryAt
Description copied from class:AMap
Gets the entry in this map at a specified index, according to the map-specific order. Caller responsible for bounds check! -
slice
Slices this Index, starting at the specified position Removes n leading entries from this Index, in key order. -
slice
-
equals
Description copied from class:ACell
Checks for equality with another Cell. In general, Cells are considered equal if they have the same canonical representation, i.e. an identical encoding with the same hash value. Subclasses SHOULD override this if they have a more efficient equals implementation. MUST NOT require reads from Store. -
equals
-
getTag
public byte getTag()Description copied from class:ACell
Gets the tag byte for this cell. The tag byte is always equal to the first byte of the Cell's canonical Encoding, and is sufficient to distinguish how to read the rest of the encoding. -
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
-
containsValue
Description copied from class:AMap
CHecks if this map contains the given value. WARNING: probably O(n) -
create
-