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:
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(Object value)create(K k, V v)empty()Returns an empty instance of the same general 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 firstintencodeRaw(byte[] bs, int pos)Writes this Cell's encoding to a byte array, excluding the tag byteentryAt(long ix)Gets the entry in this map at a specified index, according to the map-specific order.booleanChecks this BlobMap for equality with another map.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 format for message writing.booleanReturns true if this object represents a first class CVM Value.read(ByteBuffer bb)<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 mapremoveLeadingEntries(long n)Removes n leading entries from this BlobMap, in key order.Converts 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, equalsKeys, get, getEntry, getKeyRefEntry, getTypeMethods inherited from class convex.core.data.AMap
clear, conj, containsKey, containsKeyRef, entryVector, equals, get, get, get, getElementRef, keySet, print, put, putAll, remove, valuesMethods inherited from class convex.core.data.ADataStructure
conjAll, count, isEmpty, sizeMethods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, equals, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, hashCode, isEmbedded, toString, writeMethods inherited from class convex.core.data.AObject
attachEncoding, 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 format for message writing. Reading or writing a non-canonical value should be considered illegal, but non-canonical objects may be used on a temporary internal basis. -
isCVMValue
public final boolean isCVMValue()Description copied from class:ACellReturns true if this object represents a first class CVM Value. Sub-structural cells that are not themselves first class values should return false. 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. 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
-
containsValue
-
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. Contained Refs may be either external or embedded. -
getRef
Description copied from class:ACellGets a numbered child Ref from within this Cell. -
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- 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 likely to contain the entire object when represented in binary format, including the tag byte.- 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(ByteBuffer bb) 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 Valie 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 general 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. -
removeLeadingEntries
Removes n leading entries from this BlobMap, in key order.- Parameters:
n- Number of entries to remove- Returns:
- Updated BlobMap with leading entries removed.
- Throws:
IndexOutOfBoundsException- If there are insufficient entries in the BlobMap
-
equals
Checks this BlobMap for equality with another map. -
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 will be the first byte of the encoding -
toCanonical
Description copied from class:ACellConverts this Cell to its canonical version. Returns this if already canonical- Specified by:
toCanonicalin classACell- Returns:
- Canonical version of Cell
-