#不可变性 #哈希表 #函数式编程 #泛型 #并发

无 std hash-trie

Hash Array Mapped Trie (HAMT) 不可变集合实现

2 个不稳定版本

0.4.0 2021年7月12日
0.3.0 2021年5月19日
0.2.0 2021年5月15日
0.1.0 2021年5月13日
0.0.1 2021年5月13日

数据结构 中排名第 2349

MPL-2.0 许可证

315KB
5.5K SLoC

HashTrie

HashTrie 提供基于 Hash Array Mapped Tries (HAMT) 的容器。它们对并发和函数式编程友好。虽然数据结构是不可变的,但在修改时,实例之间共享了大部分内存。

HashTrieSet 实现了一个哈希集合。以下是一个快速使用示例。

use fnv::FnvHasher;
use hash_trie::HashTrieSet;

let mut hash_set: HashTrieSet<u64, u32, String, FnvHasher> = HashTrieSet::new();
let hello_world: String = "Hello, world!".into();

hash_set = hash_set.insert(&hello_world, false).unwrap().0;

// Inserting an already-inserted value returns a reference to the value in the set...
assert_eq!(*hash_set.insert(&hello_world, false).unwrap_err(), hello_world);
// ... unless you enable replacement.
assert!(hash_set.insert(&hello_world, true).is_ok());

assert_eq!(*hash_set.find(&hello_world).unwrap(), hello_world);

match hash_set.remove(&hello_world) {
    Ok((mutated, reference)) => {
        // Removing a value returns a reference to the value
        // in the set in addition to the mutated set.
        println!("Value stored in hash_set: {}", reference);
        hash_set = mutated;
    },
    Err(_) => panic!(),
}

HashTrieMap 实现了一个具有可比较语法的哈希表。

依赖项

~13–285KB