Name: cactus
Owner: Software Development Team
Description: Immutable cactus stack
Created: 2017-07-18 14:28:15.0
Updated: 2018-04-04 09:56:38.0
Pushed: 2018-04-04 10:45:36.0
Homepage: null
Size: 15
Language: Rust
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
This library provides an immutable cactus stuck (also called a spaghetti stack
or parent pointer tree). A cactus stack is a (possibly empty) node with a
(possibly null) pointer to a parent node. Any given node has a unique path back
to the root node. Rather than mutably updating the stack, one creates and
obtains access to immutable nodes (when a node becomes unreachable its memory is
automatically reclaimed). A new child node pointing to a parent can be created
via the child
function (analogous to the normal push
) and a parent can be
retrieved via the parent
function (analogous to the normal pop
).
cactus::Cactus;
c = Cactus::new();
rt!(c.is_empty());
c2 = c.child(1);
rt_eq!(c2.len(), 1);
rt_eq!(*c2.val().unwrap(), 1);
c3 = c2.parent().unwrap();
rt!(c3.is_empty());
From a given node one can create multiple sub-stacks:
cactus::Cactus;
c = Cactus::new().child(1);
c2 = c.child(2);
c3 = c.child(3);
rt!(c2 != c3);
rt_eq!(c2.vals().cloned().collect::<Vec<_>>(), [2, 1]);
rt_eq!(c3.vals().cloned().collect::<Vec<_>>(), [3, 1]);