treap_non_random 0.1.0-alpha.2

A non-randomized Treap implementation. Not very useful as a balanced tree, but useful when implementing CVM or similar algorithms.
Documentation
  • Coverage
  • 100%
    10 out of 10 items documented2 out of 10 items with examples
  • Size
  • Source code size: 18.08 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.96 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • apanda/cvm
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • apanda

A Treap library

A treap (Aragon and Siedel '89, Randomized Search Tree) is a binary search tree. Each element in the binary search tree contains a value and a priority, and the algorithm guarantees two things: (a) The binary search tree is arranged according to values, and thus in (good cases), you can find a value (or check for its existence) in O(lg n) time. (b) The root of the binary tree is always the element with the largest "priority".

Traditionally, random priorities are used and thus in expectation the tree is balanced. However, Treaps are not a particularly interesting way to build sets or hashmaps, you are better served using the standard Rust BTree instead.

This implementation exists instead to be used in cases where accessing elements with max priorities and checking existence are both necessary, as is the case with the CVM algorithm (https://cs.stanford.edu/~knuth/papers/cvm-note.pdf).

Example

use treap_non_random as treap;
use treap::{Element, Treap};

let mut t: Treap<String, i32> = Treap::new();
t.insert(Element::new("A".into(), 0));
t.insert(Element::new("lo".into(), -22));
t.insert(Element::new("hi".into(), 65536));
let max = t.get_max();
assert!(max.is_some() && max.unwrap().value().eq("hi".into()));
let lo = t.get("lo".into());
assert!(lo.is_some());
let no = t.get("missing".into());
assert!(no.is_none());