11 个版本

0.5.1 2023年7月29日
0.5.0 2022年10月24日
0.4.1 2022年10月7日
0.3.3 2022年9月23日
0.1.0 2021年10月22日

#648数据结构

每月 30 次下载

Apache-2.0

245KB
1K SLoC

trying

提供了一种简单的 Trie 实现来存储由 "原子" 组成的 "键"。

trie 对键、原子和值类型施加限制

(其中 A 代表键将表示的原子类型)

在这些限制条件下,trie 实现了一种相对高效的机制,用于

  • 前缀匹配
  • 用具有共同前缀的大量数据表示
  • 找到最短唯一前缀
  • 找到替代值
  • 找到最长公共前缀

例如

use trying::trie::TrieVec;
use unicode_segmentation::UnicodeSegmentation;

// Declare a trie which will store &str keys
// with usize values.
let mut trie = TrieVec::<&str, usize>::new();
let s = "a̐éö̲\r\n";
let input = s.graphemes(true);
// Insert our graphemes into the trie
trie.insert(input.clone());
// Anything which implements IntoIterator<Item=&str> can now be used
// to interact with our Trie
assert!(trie.contains(input.clone()));
assert!(trie.remove(input.clone()).is_none());
assert!(!trie.contains(input));

如果你不需要前缀匹配,那么 HashMap 几乎总是比 trie 更好的选择...

Crates.io

API 文档

安装

[dependencies]
trying = "0.5"

功能可用.

许可

Apache 2.0 许可。请参阅 LICENSE 以获取详细信息。

依赖项