loro/crates/rle/examples/string_tree_bench/main.rs

28 lines
868 B
Rust
Raw Normal View History

2022-08-12 12:46:38 +00:00
mod string_tree;
use rle::RleTree;
use string_tree::{CustomString, StringTreeTrait};
pub fn main() {
let mut tree: RleTree<CustomString, StringTreeTrait> = RleTree::default();
2022-08-12 18:19:43 +00:00
let len = 1e6 as usize;
let mut seed = 2;
tree.with_tree_mut(|tree| {
for i in 0..(len) {
seed = (seed * 2) % 10000007;
if tree.len() > 100000 {
2022-08-12 12:46:38 +00:00
let start = i % tree.len();
2022-08-12 18:19:43 +00:00
let len = seed % std::cmp::min(tree.len(), 1);
2022-08-12 12:46:38 +00:00
let end = std::cmp::min(start + len, tree.len());
tree.delete_range(Some(start), Some(end))
} else if tree.len() == 0 {
2022-08-12 18:19:43 +00:00
tree.insert(0, "0".into());
2022-08-12 12:46:38 +00:00
} else {
2022-08-12 18:19:43 +00:00
tree.insert(seed % tree.len(), "a".into());
2022-08-12 12:46:38 +00:00
}
2022-08-12 18:19:43 +00:00
}
2022-08-12 12:46:38 +00:00
2022-08-12 18:19:43 +00:00
println!("{} op, with tree size of {}", len, tree.len());
});
2022-08-12 12:46:38 +00:00
}