Interface PatriciaTrie<Key,Value extends Marshallable>


public interface PatriciaTrie<Key,Value extends Marshallable>
A Merkle-Patricia trie.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    A function that supplies an unmarshalling context.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    garbageCollect(long commitNumber)
    Garbage-collects all keys that have been updated during the given number of commit.
    get(Key key)
    Yields the value bound to the given key.
    byte[]
    Yields the root of the trie, that can be used as a hash of its content.
    static <Key, Value extends Marshallable>
    PatriciaTrie<Key,Value>
    of(KeyValueStore store, io.hotmoka.crypto.api.HashingAlgorithm<? super Key> hashingForKeys, io.hotmoka.crypto.api.HashingAlgorithm<? super Node> hashingForNodes, Unmarshaller<? extends Value> valueUnmarshaller, PatriciaTrie.UnmarshallingContextSupplier unmarshallingContextSupplier, long numberOfCommits)
    Yields the Merkle-Patricia trie supported by the underlying store, using the given hashing algorithm to hash nodes, keys and the values.
    void
    put(Key key, Value value)
    Binds the given key to the given value.
  • Method Details

    • get

      Optional<Value> get(Key key)
      Yields the value bound to the given key.
      Parameters:
      key - the key
      Returns:
      the value, if any
    • put

      void put(Key key, Value value)
      Binds the given key to the given value. It replaces it if already present.
      Parameters:
      key - the key
      value - the value
    • getRoot

      byte[] getRoot()
      Yields the root of the trie, that can be used as a hash of its content.
      Returns:
      the root
    • garbageCollect

      void garbageCollect(long commitNumber)
      Garbage-collects all keys that have been updated during the given number of commit.
      Parameters:
      commitNumber - the number of the commit to garbage collect
    • of

      static <Key, Value extends Marshallable> PatriciaTrie<Key,Value> of(KeyValueStore store, io.hotmoka.crypto.api.HashingAlgorithm<? super Key> hashingForKeys, io.hotmoka.crypto.api.HashingAlgorithm<? super Node> hashingForNodes, Unmarshaller<? extends Value> valueUnmarshaller, PatriciaTrie.UnmarshallingContextSupplier unmarshallingContextSupplier, long numberOfCommits)
      Yields the Merkle-Patricia trie supported by the underlying store, using the given hashing algorithm to hash nodes, keys and the values.
      Parameters:
      store - the store used to store a mapping from nodes' hashes to their content
      hashingForKeys - the hashing algorithm for the keys
      hashingForNodes - the hashing algorithm for the nodes of the trie
      valueUnmarshaller - a function able to unmarshall a value from its byte representation
      unmarshallingContextSupplier - the supplier of the unmarshalling context
      numberOfCommits - the current number of commits already executed on the store; this trie will record which data must be garbage collected (eventually) as result of the store updates performed during that commit; this could be -1L if the trie is only used or reading
      Returns:
      the trie