Package convex.core.data
Class MapEntry<K extends ACell,V extends ACell>
java.lang.Object
- Type Parameters:
K- The type of keysV- The type of values
- All Implemented Interfaces:
IAssociative<CVMLong,ACell>,IValidated,IWriteable,Comparable<MapEntry<K,V>>,Iterable<ACell>,Collection<ACell>,List<ACell>,Map.Entry<K,V>
public class MapEntry<K extends ACell,V extends ACell>
extends AMapEntry<K,V>
implements Comparable<MapEntry<K,V>>
Map.Entry implementation for persistent maps.
Contains exactly 2 Refs, one for key and one for value
Implements Comparable using the hash value of keys.
-
Field Summary
Fields inherited from class convex.core.data.ADataStructure
countFields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY -
Method Summary
Modifier and TypeMethodDescriptionassoc(long i, R a)Updates a value at the given position in the sequence.intConcatenates the elements from another sequence to the end of this sequence.booleanstatic MapEntryconvertOrNull(AVector v)protected <R> voidcopyToArray(R[] arr, int offset)Copies the elements of this collection in order to an array at the specified offsetcreate(K key, V value)Creates a new MapEntry with the provided key and valueintencode(byte[] bs, int pos)Writes this Cell's encoding to a byte array, including a tag byte which will be written firststatic intencodeCompressed(MapEntry<?,?> me, byte[] bs, int pos)Writes a MapEntry or null content in compressed format (no count).intencodeRaw(byte[] bs, int pos)Writes the raw MapEntry content.booleanChecks for equality with another object.booleanintEstimate the encoded data size for this Cell.get(long i)Gets the element at the specified index in this vectorgetElementRef(long i)Gets the element Ref at the specified indexgetKey()Gets the hash of the key for this MapEntrygetRef(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.getType()Gets the most specific known runtime Type for this Cell.getValue()booleanReturns true if this vector is in canonical format, i.e.booleanReturns true if this object represents a first class CVM Value.booleanChecks if the keys of two map entries are equalMaps a function over a collection, applying it to each element in turn.Create a map entry, converting key and value to correct CVM types.read(ByteBuffer bb)Reads a MapEntry from a ByteBuffer.readCompressed(ByteBuffer bb)Reads a MapEntry or null from a ByteBuffer.<R> Rreduce(BiFunction<? super R,? super ACell,? extends R> func, R value)subVector(long start, long length)Gets a vector containing the specified subset of this sequence.Converts this Cell to its canonical version.toVector()Converts this collection to a canonical vector of elementsupdateRefs(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.voidvisitElementRefs(Consumer<Ref<ACell>> f)Visits all elements in this sequence, calling the specified consumer for each.Create a new MapEntry with an updated key.Create a new MapEntry with an updated value.Methods inherited from class convex.core.data.AMapEntry
allMatch, anyMatch, append, appendChunk, commonPrefixLength, forEach, getChunk, isPacked, iterator, listIterator, listIterator, longIndexOf, longLastIndexOf, next, set, setValue, spliterator, toArrayMethods inherited from class convex.core.data.AVector
appendAll, conj, conjAll, cons, empty, flatMap, get, indexOf, lastIndexOf, listIterator, mergeWith, print, reverse, slice, spliterator, toArrayMethods inherited from class convex.core.data.ASequence
add, addAll, assoc, checkRange, containsKey, get, get, remove, subList, toCellArrayMethods inherited from class convex.core.data.ACollection
add, addAll, clear, containsAll, remove, removeAll, retainAllMethods inherited from class convex.core.data.ADataStructure
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.Collection
parallelStream, removeIf, stream, toArray
-
Method Details
-
getType
Description copied from class:ACellGets the most specific known runtime Type for this Cell. -
createRef
-
create
Creates a new MapEntry with the provided key and value- Type Parameters:
K- Type of KeyV- Type of value- Parameters:
key- Key to use for MapEntryvalue- Value to use for MapEntry- Returns:
- New MapEntry instance
-
of
Create a map entry, converting key and value to correct CVM types.- Type Parameters:
K- Type of KeysV- Type of Values- Parameters:
key- Key to use for map entryvalue- Value to use for map entry- Returns:
- New MapEntry
-
withValue
Description copied from class:AMapEntryCreate a new MapEntry with an updated value. Shares old key. Returns the same MapEntry if unchanged -
assoc
Description copied from class:ASequenceUpdates a value at the given position in the sequence. -
withKey
Description copied from class:AMapEntryCreate a new MapEntry with an updated key. Shares old value. Returns the same MapEntry if unchanged -
getKey
-
map
Description copied from class:ACollectionMaps a function over a collection, applying it to each element in turn. -
reduce
-
copyToArray
protected <R> void copyToArray(R[] arr, int offset)Description copied from class:ACollectionCopies the elements of this collection in order to an array at the specified offset- Specified by:
copyToArrayin classACollection<ACell>- Type Parameters:
R- Type of array elements required
-
getKeyHash
Gets the hash of the key for this MapEntry- Returns:
- the Hash of the Key
-
getValue
-
getKeyRef
-
getValueRef
-
read
public static <K extends ACell, V extends ACell> MapEntry<K,V> read(ByteBuffer bb) throws BadFormatExceptionReads a MapEntry from a ByteBuffer. Assumes Tag already handled.- Parameters:
bb- ByteBuffer to read from- Returns:
- MapEntry instance
- Throws:
BadFormatException- If encoding is invalid
-
readCompressed
public static <K extends ACell, V extends ACell> MapEntry<K,V> readCompressed(ByteBuffer bb) throws BadFormatExceptionReads a MapEntry or null from a ByteBuffer. Assumes no Tag.- Parameters:
bb- ByteBuffer to read from- Returns:
- MapEntry instance, or null
- Throws:
BadFormatException- If encoding is invalid
-
compareTo
- Specified by:
compareToin interfaceComparable<K extends ACell>
-
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. -
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.- Specified by:
updateRefsin classAVector<ACell>- Parameters:
func- Ref update function- Returns:
- Cell with updated Refs
-
equals
Description copied from class:ACellChecks for equality with another object. In general, data objects should be 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. -
equals
-
keyEquals
Checks if the keys of two map entries are equal- Parameters:
b- MapEntry to compare with this MapEntry- Returns:
- true if this entry's key equals that of the other entry, false otherwise.
-
toVector
Description copied from class:ACollectionConverts this collection to a canonical vector of elements- Specified by:
toVectorin classACollection<ACell>- Returns:
- This collection coerced to a vector
-
contains
-
get
Description copied from class:AVectorGets the element at the specified index in this vector -
getElementRef
Description copied from class:ASequenceGets the element Ref at the specified index- Specified by:
getElementRefin classASequence<ACell>- Parameters:
i- Index of element to get- Returns:
- Ref to element at specified index
-
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 -
encodeRaw
public int encodeRaw(byte[] bs, int pos)Writes the raw MapEntry content. Puts the key and value Refs onto the given ByteBuffer -
encodeCompressed
Writes a MapEntry or null content in compressed format (no count). Useful for embedding an optional MapEntry inside a larger Encoding- Parameters:
me- MapEntry to encodebs- Byte array to write topos- Starting position for encoding in byte array- Returns:
- Updated position after writing
-
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
-
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- Returns:
- The estimated size for the binary representation of this object.
-
visitElementRefs
Description copied from class:ASequenceVisits all elements in this sequence, calling the specified consumer for each.- Specified by:
visitElementRefsin classASequence<ACell>- Parameters:
f- Function to call for each element
-
concat
Description copied from class:ASequenceConcatenates the elements from another sequence to the end of this sequence. Potentially O(n) in size of resulting sequence -
subVector
Description copied from class:ASequenceGets a vector containing the specified subset of this sequence. -
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
-
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 -
convertOrNull
-
isCanonical
public boolean isCanonical()Description copied from class:AVectorReturns true if this vector is in canonical format, i.e. suitable as top-level serialised representation of a vector. -
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
-