33 releases (16 breaking)

0.28.0 Sep 12, 2023
0.27.1 Mar 17, 2023
0.26.0 Feb 24, 2023
0.24.0 Aug 4, 2022
0.12.2 Mar 29, 2019

#62 in Rust patterns

Download history 54368/week @ 2023-11-21 51963/week @ 2023-11-28 46741/week @ 2023-12-05 45785/week @ 2023-12-12 34798/week @ 2023-12-19 19440/week @ 2023-12-26 33946/week @ 2024-01-02 44049/week @ 2024-01-09 50268/week @ 2024-01-16 46436/week @ 2024-01-23 44621/week @ 2024-01-30 52830/week @ 2024-02-06 53890/week @ 2024-02-13 52802/week @ 2024-02-20 51045/week @ 2024-02-27 38713/week @ 2024-03-05

208,094 downloads per month
Used in 615 crates (10 directly)

Apache-2.0

310KB
7.5K SLoC

Build Status

Trie

A generic implementation of the Base-16 Modified Merkle Tree ("Trie") data structure, provided under the Apache2 license.

The implementation comes in two formats:

  • Trie DB (trie-db crate) which can be combined with a backend database to provide a persistent trie structure whose contents can be modified and whose root hash is recalculated efficiently.
  • Trie Root (trie-root crate) which provides a closed-form function that accepts a enumeration of keys and values and provides a root calculated entirely in-memory and closed form.

Trie Hash alone is able to be used in no_std builds by disabling its (default) std feature.

In addition to these, several support crates are provided:

  • hash-db crate, used to provide Hasher (trait for all things that can make cryptographic hashes) and HashDB (trait for databases that can have byte slices pushed into them and allow for them to be retrieved based on their hash). Suitable for no_std, though in this case will only provide Hasher.
  • memory-db crate, contains MemoryDB, an implementation of a HashDB using only in in-memory map.
  • hash256-std-hasher crate, an implementation of a std::hash::Hasher for 32-byte keys that have already been hashed. Useful to build the backing HashMap for MemoryDB.

There are also three crates used only for testing:

  • keccak-hasher crate, an implementation of Hasher based on the Keccak-256 algorithm.
  • reference-trie crate, an implementation of a simple trie format; this provides both a NodeCodec and TrieStream implementation making it suitable for both Trie DB and Trie Root.
  • trie-standardmap crate, a key/value generation tool for creating large test datasets to specific qualities.
  • trie-bench crate, a comprehensive standard benchmarking tool for trie format implementations. Works using the criterion project so benchmarking can be done with the stable rustc branch.

In the spirit of all things Rust, this aims to be reliable, secure, and high performance.

Used in the Substrate project. If you use this crate and would your project listed here, please contact us.

Buidling &c.

Building is done through cargo, as you'd expect.

Building

cargo build --all

Testing

cargo test --all

Benchmarking

cargo bench --all

Building in no_std

cargo build --no-default-features

lib.rs:

Trie interface and implementation.

Dependencies

~2MB
~27K SLoC