3 ms·
We are far, far from 100%. You can only take mutability lifetimes if you are alone. That mean for example that you can't insert in a tree without going mad. Ye
by mackwic 12y ago
We are far, far from 100%.
You can only take mutability lifetimes if you are alone. That mean for example that you can't insert in a tree without going mad. Yeah, you have to search (non-mut operation), insert (mut operation), and balance your tree (mut operation). Not possible.
How do you do it in the official B-Tree implementation ? You clone all the branch at each insertion[1] so that the insertion don't compete with the search. Oh well.
Hopefully it's a B-Tree so it won't be too deep. But for a performance oriented language, it's make me cry a little.
[1]: a) https://github.com/rust-lang/rust/blob/master/src/libcollections/btree.rs#L68 https://github.com/rust-lang/rust/blob/master/src/libcollect...
b) https://github.com/rust-lang/rust/blob/master/src/libcollections/btree.rs#L358 https://github.com/rust-lang/rust/blob/master/src/libcollect...
- pcwalton 12y agoThe btree is very immature. TreeMap is better. It demonstrates that these operations can be done fairly naturally with swaps: https://github.com/rust-lang/rust/blob/master/src/libcollections/treemap.rs https://github.com/rust-lang/rust/blob/master/src/libcollect...
- mackwic 12y agoYes, I can see that. And there is also a bunch of interesting patterns to learn from. Please understand that by no mean I want to discredit your work. Rust is a great thing, and will be amazing. However, a random programmer alone in the jungle with only the rustc and the doc will had a hard time to express whatever he likes. It will get better, I trust you. Just don't let the hype grow too fast as Rust is not ready yet, not only in features but also in accessibility.