Skip to content

Instantly share code, notes, and snippets.

@Heimdell
Created December 13, 2020 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Heimdell/863df984e88707857d4b34878f2b945f to your computer and use it in GitHub Desktop.
Save Heimdell/863df984e88707857d4b34878f2b945f to your computer and use it in GitHub Desktop.
use std::sync::Arc;
enum Octree<B, A>
{ Branch
{ preview : B
, subtrees : [Arc<Octree<B, A>>; 8]
}
, Atom
{ leaf : A
, preview : B
}
}
type Path = Vec<usize>;
trait IsOctree<'bounded> {
fn lookup(path : Path, it : &'bounded Arc<Self>) -> &'bounded Arc<Self>;
// fn update(path : Path, value : Self, it : &Self) -> Self;
}
impl <'bounded, A : 'static, B : 'static> IsOctree<'bounded> for Octree<B, A> {
fn lookup(path : Path, it : &'bounded Arc<Octree <B, A>>) -> &'bounded Arc<Octree<B, A>> {
let mut ptr = it;
for i in path {
match &**ptr {
| Octree::Atom {leaf, preview} => return &ptr,
| Octree::Branch {preview, subtrees} =>
ptr = &subtrees[i]
}
}
return &it
}
// fn update(path : Path, val : Octree <B, A>, it : &Octree <B, A>) -> Octree<B, A> {
// return *it
// }
}
fn main() {
println!("Hello, world!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment