1,205 karma · joined July 10, 2019
Rebalancing of the left branch is a bit complicated, so I implemented just detach() method, which takes out the element with it subbranches from the tree. From there, you can implement your favorite deletion method. For production, I will just mark a node as deleted and then compact the tree later, to have predictable timings.
#[derive(Debug)]
struct Node {
data: i32,
left: Option<Box<Node>>,
right: Option<Box<Node>>,
parent: Option<*mut Node>,
}
impl Node {
pub fn new_root(data: i32) -> Self {
Node { data, left: None, right: None, parent: None, }
}
pub fn new_leaf(data: i32, parent: *mut Node) -> Self {
Node { data, left: None, right: None, parent: Some(parent), }
}
}
#[derive(Debug)]
struct Tree {
root: Option<Node>,
}
impl Tree {
pub fn new() -> Self {
Tree { root: None }
}
pub fn insert(&mut self, data: i32) -> bool {
match self.root {
Some(ref mut node) => Tree::insert_at(node, data),
None => {
self.root = Some(Node::new_root(data));
true
}
}
}
fn insert_at(current_node: &mut Node, data: i32) -> bool {
match (
current_node.left.as_deref_mut(),
current_node.right.as_deref_mut(),
) {
_ if data == current_node.data => false,
(Some(left_node), _) if data < current_node.data => Tree::insert_at(left_node, data),
(None, _) if data < current_node.data => {
let new_node = Node::new_leaf(data, current_node);
current_node.left = Some(Box::new(new_node));
true
}
(_, Some(right_node)) => Tree::insert_at(right_node, data),
(_, None) => {
let new_node = Node::new_leaf(data, current_node);
current_node.right = Some(Box::new(new_node));
true
}
}
}
}
pub fn main() {
let mut tree = Tree::new();
let data = [5, 3, 65, 123, 6, 11, 3, 1, 5, 42];
for i in data {
tree.insert(i);
}
println!("{:?}", tree);
} Compiling gltf v0.11.3
error[E0597]: `buf` does not live long enough
--> /home/vlisivka/.cargo/registry/src/github.com-1ecc6299db9ec823/gltf-0.11.3/src/binary.rs:225:35
|
119 | impl<'a> Glb<'a> {
| -- lifetime `'a` defined here
...
225 | Self::from_v2(&buf)
| --------------^^^^-
| | |
| | borrowed value does not live long enough
| argument requires that `buf` is borrowed for `'a`
...
233 | }
| - `buf` dropped here while still borrowedAlice can forcefully change her sock from left sock to right sock and back, e.g. by putting sock to the corresponding foots, but Bob will never know that.
I can just record the clock and replay the record. It makes back-in-time travel much simpler then.
[0]: https://ae01.alicdn.com/kf/HTB1UMz3k8yWBuNkSmFPq6xguVXar/1pc...
Efficacy is just estimation after some tests. It must be at least 50% for vaccine to be accepted. 95% is bigger than 50%.
«Some folks, which are used to use proofs, are accepting something without proof...» Emmm...