Skip to content
This repository has been archived by the owner on Sep 13, 2021. It is now read-only.
/ PinTree Public archive

HashMap/Set<Pin<Arc<T>>> based fully safety tree collection

License

Notifications You must be signed in to change notification settings

2A5F/PinTree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PinTree

HashMap/Set<Pin<Arc<T>>> based fully safety tree collection

Examples

let mut pt = PinTree::<i32>::new();

let a = &pt.node(1);
let b = &pt.node(2);
let c = &pt.node(3);

pt.set_parent(b, a);
pt.set_parent(c, a);
//    a
//  ↙  ↘
// b     c

assert_eq!(pt.is_parent(b, a), true);
assert_eq!(pt.is_child(a, c), true);
// Circular references are safe
pt.set_parent(b, a);
pt.set_parent(a, c);
pt.set_parent(c, b);
//    a
//  ↙  ↖
// b  →  c

pt.set_parent(a, a);
// a ⟲
let mut pt = PinTree::<Mutex<i32>>::new();

let a = pt.node(Mutex::new(1));
let mut x = a.lock().unwrap();
assert_eq!(*x, 1);
*x = 2;
assert_eq!(*x, 2);