53 个版本 (28 个破坏性版本)
0.77.2 | 2024 年 2 月 16 日 |
---|---|
0.76.1 | 2024 年 2 月 13 日 |
0.60.0 | 2023 年 12 月 27 日 |
0.57.1 | 2023 年 10 月 10 日 |
0.27.0 |
|
#218 in 数据结构
每月 141 次下载
用于 16 个 crate (3 个直接使用)
49KB
1K SLoC
avltriee
特性
AVLTree 的定制版本。处理第三分支上的相同值。这允许在值分布的基数较小的情况下进行高效搜索。
一个数据在行之间不可移动,并且左右和父等位置关系都通过行号引用。通过指定行号不需要搜索即可引用值。
示例
初始化
use avltriee::Avltriee;
let mut triee = Avltriee::new();
插入和更新
unsafe {
triee.insert(&100); //or triee.update(1.try_into().unwrap(), &100);
}
unsafe {
triee.insert(&345); //or triee.update(2.try_into().unwrap(), &345);
}
unsafe {
triee.insert(&789); //or triee.update(3.try_into().unwrap(), &789);
}
unsafe {
triee.update(2.try_into().unwrap(), &1234); //update exists row
}
迭代器
for i in triee.iter() {
println!("{}:{}", i, unsafe{ t.value_unchecked(i) });
}
for i in triee.desc_iter() {
println!("{}:{}", i, unsafe{ t.value_unchecked(i) });
}
for i in t.iter_from(&10) {
println!("{}:{}", i, unsafe{ t.value_unchecked(i) });
}
for i in t.iter_to(&500) {
println!("{}:{}", i, unsafe{ t.value_unchecked(i) });
}
for i in t.iter_range(&300,&999) {
println!("{}:{}", i, unsafe{ t.value_unchecked(i) });
}
删除
triee.delete(1.try_into().unwrap());
搜索
let (ord,row) = triee.search(&100);
if ord==Ordering::Equal{
//found
}
依赖项
~1MB
~16K SLoC