Class BlobMap<K extends ABlob,V extends ACell>

Type Parameters:
K - Type of Keys
V - Type of values
All Implemented Interfaces:
IValidated, IWriteable, Map<K,V>

public class BlobMap<K extends ABlob,V extends ACell> extends ABlobMap<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
  • Field Details

  • Constructor Details

    • BlobMap

      protected BlobMap(long depth, long prefixLength, MapEntry<K,V> entry, Ref<BlobMap>[] entries, short mask, long count)
  • Method Details

    • create

      public static <K extends ABlob, V extends ACell> BlobMap<K,V> create(MapEntry<K,V> me)
    • create

      public static <K extends ABlob, V extends ACell> BlobMap<K,V> create(K k, V v)
    • of

      public static <K extends ABlob, V extends ACell> BlobMap<K,V> of(Object k, Object v)
    • 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).
      Overrides:
      isCanonical in class ABlobMap<K extends ABlob,V extends ACell>
      Returns:
      true if the object is in canonical format, false otherwise
    • 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 class ACell
      Returns:
      true if the object is a CVM Value, false otherwise
    • updateRefs

      public BlobMap<K,V> updateRefs(IRefFunction func)
      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 class ACell
      Parameters:
      func - Ref update function
      Returns:
      Cell with updated Refs
    • containsValue

      public boolean containsValue(Object value)
    • get

      public V get(ABlob key)
      Description copied from class: ABlobMap
      Gets the map entry for a given blob
      Specified by:
      get in class ABlobMap<K extends ABlob,V extends ACell>
      Parameters:
      key - Key to lookup up
      Returns:
      The value specified by the given blob key or null if not present.
    • getEntry

      public MapEntry<K,V> getEntry(ABlob key)
      Specified by:
      getEntry in class ABlobMap<K extends ABlob,V extends ACell>
    • 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.
      Specified by:
      getRefCount in class ABlobMap<K extends ABlob,V extends ACell>
      Returns:
      The number of Refs in this Cell
    • getRef

      public <R extends ACell> Ref<R> getRef(int i)
      Description copied from class: ACell
      Gets a numbered child Ref from within this Cell.
      Specified by:
      getRef in class ABlobMap<K extends ABlob,V extends ACell>
      Type Parameters:
      R - Type of referenced Cell
      Parameters:
      i - Index of ref to get
      Returns:
      The Ref at the specified index
    • assoc

      public BlobMap<K,V> assoc(ACell key, ACell value)
      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
      Specified by:
      assoc in class ABlobMap<K extends ABlob,V extends ACell>
      Parameters:
      key - Map key to associate
      value - Map value
      Returns:
      An updated map with the new association, or null if the association fails
    • dissoc

      public BlobMap<K,V> dissoc(ABlob k)
      Specified by:
      dissoc in class ABlobMap<K extends ABlob,V extends ACell>
    • accumulateEntrySet

      protected void accumulateEntrySet(HashSet<Map.Entry<K,V>> h)
      Description copied from class: AMap
      Accumulate all entries from this map in the given HashSet.
      Specified by:
      accumulateEntrySet in class AMap<K extends ABlob,V extends ACell>
      Parameters:
      h - HashSet in which to accumulate entries
    • accumulateKeySet

      protected void accumulateKeySet(HashSet<K> h)
      Description copied from class: AMap
      Accumulate all keys from this map in the given HashSet.
      Specified by:
      accumulateKeySet in class AMap<K extends ABlob,V extends ACell>
      Parameters:
      h - HashSet in which to accumulate keys
    • accumulateValues

      protected void accumulateValues(ArrayList<V> al)
      Description copied from class: AMap
      Accumulate all values from this map in the given ArrayList.
      Specified by:
      accumulateValues in class AMap<K extends ABlob,V extends ACell>
      Parameters:
      al - ArrayList in which to accumulate values
    • forEach

      public void forEach(BiConsumer<? super K,? super V> action)
      Specified by:
      forEach in interface Map<K extends ABlob,V extends ACell>
      Specified by:
      forEach in class AMap<K extends ABlob,V extends ACell>
    • assocEntry

      public BlobMap<K,V> assocEntry(MapEntry<K,V> e)
      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.
      Specified by:
      assocEntry in class AMap<K extends ABlob,V extends ACell>
      Parameters:
      e - A map entry
      Returns:
      The updated map
    • reduceValues

      public <R> R reduceValues(BiFunction<? super R,? super V,? extends R> func, R initial)
      Description copied from class: AMap
      Reduce over all values in this map
      Specified by:
      reduceValues in class AMap<K extends ABlob,V extends ACell>
      Type Parameters:
      R - Type of reduction return value
      Parameters:
      func - A function taking the reduction value and a map value
      initial - Initial reduction value
      Returns:
      The final reduction value
    • reduceEntries

      public <R> R reduceEntries(BiFunction<? super R,MapEntry<K,V>,? extends R> func, R initial)
      Description copied from class: AMap
      Reduce over all map entries in this map
      Specified by:
      reduceEntries in class AMap<K extends ABlob,V extends ACell>
      Type Parameters:
      R - Type of reduction return value
      Parameters:
      func - A function taking the reduction value and a map entry
      initial - Initial reduction value
      Returns:
      The final reduction value
    • filterValues

      public BlobMap<K,V> filterValues(Predicate<V> pred)
      Description copied from class: AMap
      Filters all values in this map with the given predicate.
      Overrides:
      filterValues in class AMap<K extends ABlob,V extends ACell>
      Parameters:
      pred - A predicate specifying which elements to retain.
      Returns:
      The updated map containing those entries where the predicate returned true.
    • 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 interface IWriteable
      Specified by:
      encode in class ACell
      Parameters:
      bs - A byte array to which to write the encoding
      pos - 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.
      Specified by:
      encodeRaw in class ACell
      Parameters:
      bs - A byte array to which to write the encoding
      pos - The offset into the byte array
      Returns:
      New position after writing
    • 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 interface IWriteable
      Specified by:
      estimatedEncodingSize in class ABlobMap<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

      protected MapEntry<K,V> getEntryByHash(Hash hash)
      Description copied from class: AMap
      Gets the map entry with the specified hash
      Specified by:
      getEntryByHash in class AMap<K extends ABlob,V extends ACell>
      Parameters:
      hash - Hash of key to lookup
      Returns:
      The specified MapEntry, or null if not found.
    • validate

      public void validate() throws InvalidDataException
      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:
      1. Call super.validate() - which will indirectly call validateCell()
      2. Call validate() on any contained cells in this class
      Specified by:
      validate in interface IValidated
      Overrides:
      validate in class ACell
      Throws:
      InvalidDataException - If the data Value is invalid in any way
    • validateCell

      public void validateCell() throws InvalidDataException
      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 class ACell
      Throws:
      InvalidDataException - If the Cell is invalid
    • empty

      public BlobMap<K,V> empty()
      Description copied from class: ADataStructure
      Returns an empty instance of the same Type as this data structure.
      Specified by:
      empty in class ADataStructure<MapEntry<K extends ABlob,V extends ACell>>
      Returns:
      An empty data structure
    • entryAt

      public MapEntry<K,V> entryAt(long ix)
      Description copied from class: AMap
      Gets the entry in this map at a specified index, according to the map-specific order.
      Specified by:
      entryAt in class ABlobMap<K extends ABlob,V extends ACell>
      Parameters:
      ix - Index of entry
      Returns:
      MapEntry at the specified index.
    • removeLeadingEntries

      public BlobMap<K,V> removeLeadingEntries(long n)
      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

      public boolean equals(AMap<K,V> a)
      Checks this BlobMap for equality with another map.
      Parameters:
      a - Map to compare with
      Returns:
      true if maps are equal, false otherwise.
    • equals

      public boolean equals(BlobMap<K,V> a)
      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
      Specified by:
      getTag in class ACell
      Returns:
      Tag byte for this Cell
    • toCanonical

      public ACell 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 class ACell
      Returns:
      Canonical version of Cell