Module io.hotmoka.patricia
Package io.hotmoka.patricia
Interface PatriciaTrie<Key,Value extends Marshallable>
public interface PatriciaTrie<Key,Value extends Marshallable>
A Merkle-Patricia trie.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA function that supplies an unmarshalling context. -
Method Summary
Modifier and TypeMethodDescriptionvoidgarbageCollect(long commitNumber) Garbage-collects all keys that have been updated during the given number of commit.Yields the value bound to the given key.byte[]getRoot()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.voidBinds the given key to the given value.
-
Method Details
-
get
Yields the value bound to the given key.- Parameters:
key- the key- Returns:
- the value, if any
-
put
Binds the given key to the given value. It replaces it if already present.- Parameters:
key- the keyvalue- 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 contenthashingForKeys- the hashing algorithm for the keyshashingForNodes- the hashing algorithm for the nodes of the trievalueUnmarshaller- a function able to unmarshall a value from its byte representationunmarshallingContextSupplier- the supplier of the unmarshalling contextnumberOfCommits- 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
-