Ellipsis-Labs / sokoban

Compact, efficient data structures in contiguous byte arrays
https://docs.rs/lib-sokoban/latest/sokoban
MIT License
102 stars 17 forks source link

Add avl tree implementation #2

Closed febo closed 2 years ago

febo commented 2 years ago

PR to add an AVL tree implementation using the NodeAllocator. AVL trees (theoretically) offer faster lookups as trees are more strictly balanced compared to red-black ones – although they can be slower at insert/remove operations given that they require more rotations to maintain the tree balanced.

The tests included are the same ones as the red-black tree. Adding lookup tests for both avl and red-black trees can illustrate the difference in performance:

for _ in 0..200 {
    for k in keys.iter() {
        assert!(tree.get(k) != None);
    }
}
jarry-xiao commented 2 years ago

This is super cool! Will take a look later today

jarry-xiao commented 2 years ago

Approved!