scapegoat
Ordered set and map data structures via an arena-based scapegoat tree (memory-efficient, self-balancing binary search tree).
About
Three APIs:
Strives for two properties:
-
Maximal safety: strong memory safety guarantees.
- Compile-time safety: no
unsafe(no raw pointer dereference, etc.). - Debug-time safety:
debug_assert!for logical invariants exercised in testing. - Runtime safety: no interior mutability (e.g. no need for
Rc<RefCell<T>>'s runtime check).
- Compile-time safety: no
-
Minimal footprint: small binary (no dependencies outside of the standard library) with low resource use.
- Memory-efficient: nodes have only child index metadata, node memory is re-used.
- Recursion-free: all operations are iterative, so stack use and runtime are both minimized.
- Zero-copy: rebuild/removal re-point in-place, nodes are never copied or cloned.
Other features:
- Generic: map keys and set elements can be any type that implements the
Ordtrait. - Arbitrarily mutable: elements can be insert and removed, map values can be mutated.
Usage
SGMap non-exhaustive API example (would work identically for std::collections::BTreeMap):
use SGMap;
let mut example = new;
example.insert;
example.insert;
example.insert;
example.insert;
assert_eq!;
assert_eq!;
let please_tuple = example.pop_first.unwrap;
assert_eq!;
example.insert;
let dont_blame = example.get_mut.unwrap;
dont_blame.remove;
dont_blame.insert;
assert_eq!;
Note
This project is an exercise in safe datastructure design. It's not as mature, fast, or memory efficient as the standard library's BTreeMap/BTreeSet.