Ordered set and map data structures via an arena-based scapegoat tree (memory-efficient, self-balancing binary search tree).
Three APIs:
SGTree
)SGSet
)SGMap
)Strives for two properties:
Maximal safety: strong memory safety guarantees.
unsafe
(no raw pointer dereference, etc.).debug_assert!
for logical invariants exercised in testing.Rc<RefCell<T>>
's runtime check).Minimal footprint: small binary (no dependencies outside of the standard library) with low resource use.
Other features:
Ord
trait.SGMap
non-exhaustive API example (would work identically for std::collections::BTreeMap
):
```rust use scapegoat::SGMap;
let mut example = SGMap::new();
example.insert(3, String::from("the")); example.insert(2, String::from("don't blame")); example.insert(1, String::from("Please")); example.insert(4, String::from("borrow checker"));
asserteq!(
(&example).intoiter().map(|(_, v)| v).collect::
let pleasetuple = example.popfirst().unwrap(); asserteq!(pleasetuple, (1, String::from("Please")));
example.insert(5, String::from("! :P"));
let dontblame = example.getmut(&2).unwrap(); dontblame.remove(0); dontblame.insert(0, 'D');
asserteq!(
example.intoiter().map(|(_, v)| v).collect::