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
count
Fields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
accumulateEntrySet(HashSet<Map.Entry<K,V>> h)
Accumulate all entries from this map in the given HashSet.protected void
accumulateKeySet(HashSet<K> h)
Accumulate all keys from this map in the given HashSet.protected void
accumulateValues(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.boolean
containsValue(Object 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 this BlobMap for equality with another map.boolean
Checks this BlobMap for equality with another BlobMapint
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 for message writing.boolean
Returns true if this Cell represents a first class CVM Value.read(ByteBuffer bb)
<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 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.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.ABlobMap
containsKey, dissoc, entrySet, equalsKeys, get, getEntry, getKeyRefEntry, getType
Methods inherited from class convex.core.data.AMap
clear, conj, containsKey, containsKeyRef, entryVector, equals, get, get, get, getElementRef, keySet, print, put, putAll, remove, slice, values
Methods inherited from class convex.core.data.ADataStructure
conjAll, count, isEmpty, size, toCVMString
Methods inherited from class convex.core.data.ACountable
slice
Methods 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, toString, write
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
Empty BlobMap singleton
-
-
Constructor Details
-
BlobMap
-
-
Method Details
-
create
-
create
-
of
-
isCanonical
public boolean isCanonical()Description copied from class:ACell
Returns 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:ACell
Returns 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:
isCVMValue
in classACell
- Returns:
- true if the object is a CVM 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. 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
-
containsValue
-
get
Description copied from class:ABlobMap
Gets the map entry for a given blob -
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. -
assoc
Description copied from class:ABlobMap
Associates 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:AMap
Accumulate all entries from this map in the given HashSet. -
accumulateKeySet
Description copied from class:AMap
Accumulate all keys from this map in the given HashSet. -
accumulateValues
Description copied from class:AMap
Accumulate all values from this map in the given ArrayList. -
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 likely to contain the entire object when represented in binary format, including the tag byte.- Specified by:
estimatedEncodingSize
in interfaceIWriteable
- Specified by:
estimatedEncodingSize
in 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: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 Valie 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
Description copied from class:ADataStructure
Returns an empty instance of the same Type as this data structure. -
entryAt
Description copied from class:AMap
Gets 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:ACell
Gets the tag byte for this cell. The tag byte is always written as the first byte of the Cell's Encoding -
toCanonical
Description copied from class:ACell
Converts this Cell to its canonical version. Returns this Cell if already canonical, may be O(n) in size of value otherwise.- Specified by:
toCanonical
in classACell
- Returns:
- Canonical version of Cell
-