Prefix tree implemented in Rust.

Overview

Prefix tree implemented in rust.

A simple library that provides a prefix tree (trie) implementation. It uses generic types for both keys and values.

pub struct Trie<K, V>
where
    K: Eq + Hash,
    V: Clone,
{
    nodes: HashMap<K, Trie<K, V>>,
    value: Option<V>,
}

Usage

use trie::{Trie, trie};

let mut t = Trie::new();
t.insert("foo".bytes(), 0.1);
assert_eq!(t.get("foo".bytes()), Some(0.1));
assert_eq!(t.get("not defined".bytes()), None);

// Trie supports reasignment.
let mut t = Trie::new();
t.insert("foo".bytes(), 1);
assert_eq!(t.get("foo".bytes()), Some(1));
t.insert("foo".bytes(), 2);
assert_eq!(t.get("foo".bytes()), Some(2));

// You can also create a Trie using the trie! macro.
let mut t = trie!();
t.insert("foobar".bytes(), 123);
t.insert("barfoo".bytes(), 456);
assert_eq!(t.get("foobar".bytes()), Some(123));
assert_eq!(t.get("barfoo".bytes()), Some(456));


// The trie! macro is also capable of creating a Trie with already assigned values.
let t = trie! {
    vec![1, 2] => "aaa",
    vec![1, 2, 3] => "bbb",
};
assert_eq!(t.get(vec![1, 2]), Some("aaa"));
assert_eq!(t.get(vec![1, 2, 3]), Some("bbb"));
You might also like...
k-dimensional tree

kd-tree k-dimensional tree in Rust. Fast, simple, and easy to use. Usage // construct kd-tree let kdtree = kd_tree::KdTree::build_by_ordered_float(vec

Semantic find-and-replace using tree-sitter-based macro expansion

Semantic find-and-replace using tree-sitter-based macro expansion

lemmy-help is a emmylua parser as well as a CLI which takes that parsed tree and converts it into vim help docs.
lemmy-help is a emmylua parser as well as a CLI which takes that parsed tree and converts it into vim help docs.

lemmy-help is a emmylua parser as well as a CLI which takes that parsed tree and converts it into vim help docs.

Tree-based TUI chat client
Tree-based TUI chat client

cove Cove is a TUI client for euphoria.io, a threaded real-time chat platform. It runs on Linux, Windows and macOS. Manual installation This section c

Work in progress NCBI's Common Tree alternative in the terminal

Lomanai Usage lomanai --species 'Mus musculus' --species 'Homo sapiens' # Mammalia # ++Rodentia # | \-Mus musculus # \+Primates # \-Homo sapien

Mypyc DSL grammar for tree-sitter
Mypyc DSL grammar for tree-sitter

tree-sitter-mypyc Mypyc DSL grammar for tree-sitter. Installing (Neovim) This is based on the Neovim Tree-sitter docs for adding new parsers. Basicall

tree-sitter meets Kakoune

kak-tree-sitter This is a binary server that interfaces tree-sitter with kakoune. Features Install Usage Design Credits Features Semantic highlighting

rehype plugin to use tree-sitter to highlight code in pre code blocks

rehype-tree-sitter rehype plugin to use tree-sitter to highlight code in precode blocks Contents What is this? When should I use this? Install Use

A simple, fast, and easy to use Solidity test generator based on the Branching Tree Technique.

bulloak A simple, fast, and easy to use Solidity test generator based on the Branching Tree Technique. Installing cargo install bulloak Usage Basic Us

Owner
Bailey
lisp and rust fanatic. he/him
Bailey
Traversal of tree-sitter Trees and any arbitrary tree with a TreeCursor-like interface

tree-sitter-traversal Traversal of tree-sitter Trees and any arbitrary tree with a TreeCursor-like interface. Using cursors, iteration over the tree c

Sebastian Mendez 12 Jan 8, 2023
As-tree - Print a list of paths as a tree of paths 🌳

as-tree Print a list of paths as a tree of paths. For example, given: dir1/foo.txt dir1/bar.txt dir2/qux.txt it will print: . ├── dir1 │ ├── foo.tx

Jake Zimmerman 396 Dec 10, 2022
Non-Recursive Inverting of Binary Tree in Rust

Non-Recursive Inverting of Binary Tree in Rust The idea is to implement the classical Inverting of Binary Tree but without using recursion. Quick Star

Tsoding 15 Dec 6, 2022
A syntax highlighter for Node powered by Tree Sitter. Written in Rust.

tree-sitter-highlight A syntax highlighter for Node.js powered by Tree Sitter. Written in Rust. Usage The following will output HTML: const treeSitter

Devon Govett 211 Dec 20, 2022
Basic template for an out-of-tree Linux kernel module written in Rust.

Rust out-of-tree module This is a basic template for an out-of-tree Linux kernel module written in Rust. Please note that: The Rust support is experim

Rust for Linux 118 Dec 26, 2022
An Rust implementation of the Modified Merkle Patricia Tree described by ETH Yellow Paper

Merkle Patricia Tree的Rust实现 博客文章:https://dere.press/2022/01/24/eth-trie/ 本实现参考下列项目: https://ethereum.github.io/yellowpaper/paper.pdf https://github.co

M4tsuri 3 Dec 13, 2022
Build Abstract Syntax Trees and tree-walking models quickly in Rust.

astmaker Build Abstract Syntax Trees and tree-walking models quickly in Rust. Example This example creates an AST for simple math expressions, and an

David Delassus 100 Jun 5, 2023
Like grep, but uses tree-sitter grammars to search

tree-grepper Works like grep, but uses tree-sitter to search for structure instead of strings. Installing This isn't available packaged anywhere. That

Brian Hicks 219 Dec 25, 2022
Tree-sitter - An incremental parsing system for programming tools

tree-sitter Tree-sitter is a parser generator tool and an incremental parsing library. It can build a concrete syntax tree for a source file and effic

null 10.6k Jan 9, 2023
A tree-sitter based AST difftool to get meaningful semantic diffs

diffsitter Disclaimer diffsitter is very much a work in progress and nowhere close to production ready (yet). Contributions are always welcome! Summar

Afnan Enayet 1.3k Jan 8, 2023