Package convex.core.data
Class BlobMap<K extends ABlob,V extends ACell>
java.lang.Object
convex.core.data.AObject
convex.core.data.ACell
convex.core.data.ACountable<E>
convex.core.data.ADataStructure<MapEntry<K,V>>
convex.core.data.AMap<K,V>
convex.core.data.ABlobMap<K,V>
convex.core.data.BlobMap<K,V>
- Type Parameters:
K- Type of KeysV- Type of values
- All Implemented Interfaces:
IAssociative<K,,V> IValidated,IWriteable,Map<K,V>
BlobMap node implementation supporting:
- An optional prefix string
- An optional entry with this 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
countFields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaccumulateEntrySet(HashSet<Map.Entry<K, V>> h) Accumulate all entries from this map in the given HashSet.protected voidaccumulateKeySet(HashSet<K> h) Accumulate all keys from this map in the given HashSet.protected voidaccumulateValues(ArrayList<V> al) Accumulate all values from this map in the given ArrayList.Associates a blob key with a value in this data structure.assocEntry(MapEntry<K, V> e) Associate the given map entry into the map.booleancontainsValue(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.intencode(byte[] bs, int pos) Writes this Cell's encoding to a byte array, including a tag byte which will be written first.intencodeRaw(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.booleanChecks for equality with another Cell.booleanChecks this BlobMap for equality with another BlobMapintEstimate the encoded data size for this Cell.filterValues(Predicate<V> pred) Filters all values in this map with the given predicate.voidforEach(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.intGets the number of Refs contained within this Cell.bytegetTag()Gets the tag byte for this cell.booleanReturns true if this Cell is in a canonical representation for message writing.final booleanReturns true if this Cell represents a first class CVM Value.<R> RreduceEntries(BiFunction<? super R, MapEntry<K, V>, ? extends R> func, R initial) Reduce over all map entries in this map<R> RreduceValues(BiFunction<? super R, ? super V, ? extends R> func, R initial) Reduce over all values in this mapslice(long start) Slices this BlobMap, starting at the specified position Removes n leading entries from this BlobMap, in key order.slice(long start, long end) Returns a slice of this BlobMapConverts this Cell to its canonical version.updateRefs(IRefFunction func) Updates all Refs in this object using the given function.voidvalidate()Validates the complete structure of this object.voidValidates the local structure and invariants of this cell.Methods inherited from class convex.core.data.ABlobMap
containsKey, dissoc, entrySet, get, getEntry, getKeyRefEntry, getTypeMethods inherited from class convex.core.data.AMap
clear, conj, containsKey, containsKeyRef, containsValue, entryVector, get, get, get, getElementRef, getKeys, keySet, merge, print, put, putAll, remove, valuesMethods inherited from class convex.core.data.ADataStructure
checkIndex, conjAll, count, isEmpty, size, toCVMStringMethods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, equals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, hashCode, isCompletelyEncoded, isEmbedded, mark, mark, toStringMethods inherited from class convex.core.data.AObject
attachEncoding, print, printMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, getOrDefault, hashCode, isEmpty, merge, putIfAbsent, remove, replace, replace, replaceAll, size
-
Field Details
-
EMPTY
Empty BlobMap singleton
-
-
Constructor Details
-
BlobMap
-
-
Method Details
-
create
-
create
-
of
-
isCanonical
public boolean isCanonical()Description copied from class:ACellReturns true if this Cell is in a canonical representation for message writing. Non-canonical objects may be used on a temporary internal basis, they must always be converted to canonical representations for external use (e.g. Encoding). -
isCVMValue
public final boolean isCVMValue()Description copied from class:ACellReturns true if this Cell represents a first class CVM Value. Sub-structural cells that are not themselves first class values 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:
isCVMValuein classACell- Returns:
- true if the object is a CVM Value, false otherwise
-
updateRefs
Description copied from class:ACellUpdates 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:
updateRefsin classACell- Parameters:
func- Ref update function- Returns:
- Cell with updated Refs
-
get
Description copied from class:ABlobMapGets the map entry for a given blob -
getEntry
-
getRefCount
public int getRefCount()Description copied from class:ACellGets 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. WARNING: may not be valid id Cell is not canonical Contained Refs may be either external or embedded. -
getRef
Description copied from class:ACellGets a numbered child Ref from within this Cell. WARNING: May be unreliable is cell is not canonical -
assoc
Description copied from class:ABlobMapAssociates a blob key with a value in this data structure. Returns null if the key is not a valid BlobMap key -
dissoc
-
accumulateEntrySet
Description copied from class:AMapAccumulate all entries from this map in the given HashSet. -
accumulateKeySet
Description copied from class:AMapAccumulate all keys from this map in the given HashSet. -
accumulateValues
Description copied from class:AMapAccumulate all values from this map in the given ArrayList. -
forEach
-
assocEntry
Description copied from class:AMapAssociate 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:AMapReduce over all values in this map -
reduceEntries
Description copied from class:AMapReduce over all map entries in this map -
filterValues
Description copied from class:AMapFilters all values in this map with the given predicate. -
encode
public int encode(byte[] bs, int pos) Description copied from class:ACellWrites 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:
encodein interfaceIWriteable- Specified by:
encodein 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:ACellWrites this Cell's encoding to a byte array, excluding the tag byte. -
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 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:
estimatedEncodingSizein interfaceIWriteable- Specified by:
estimatedEncodingSizein classABlobMap<K extends ABlob,V extends ACell> - Returns:
- The estimated size for the binary representation of this object.
-
read
public static <K extends ABlob,V extends ACell> BlobMap<K,V> read(Blob b, int pos) throws BadFormatException - Throws:
BadFormatException
-
getEntryByHash
Description copied from class:AMapGets the map entry with the specified hash -
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 classACell- Throws:
InvalidDataException- If the data Value is invalid in any way
-
validateCell
Description copied from class:ACellValidates 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:
validateCellin classACell- Throws:
InvalidDataException- If the Cell is invalid
-
empty
Description copied from class:ADataStructureReturns an empty instance of the same Type as this data structure. -
entryAt
Description copied from class:AMapGets the entry in this map at a specified index, according to the map-specific order. Caller responsible for bounds check! -
slice
Slices this BlobMap, starting at the specified position Removes n leading entries from this BlobMap, in key order. -
slice
Returns a slice of this BlobMap -
equals
Description copied from class:ACellChecks 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
Checks this BlobMap for equality with another BlobMap- Parameters:
a- BlobMap to compare with- Returns:
- true if maps are equal, false otherwise.
-
getTag
public byte getTag()Description copied from class:ACellGets 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:ACellConverts this Cell to its canonical version. Must return this Cell if already canonical, may be O(n) in size of value otherwise.- Specified by:
toCanonicalin classACell- Returns:
- Canonical version of Cell
-
containsValue
Description copied from class:AMapCHecks if this map contains the given value. WARNING: probably O(n)
-