-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
The nested
scheme (and therefore unique
, too) is hierarchical, and thus it is possible to have the arrange the cells into a tree. For various applications (e.g. aggregation) it is important to be able to query the hierarchy for parents, siblings, children. This can be as simple as
fn parent(&self, cell_id: u64, depth: u8) -> u64 {
if self.depth < depth {
panic!("Parent depth must be smaller than current depth, but got {} and {}", depth, self.depth)
} elif self.depth == depth {
cell_id
} else {
cell_id >> (2 * (self.depth - depth))
}
}
fn siblings(&self, cell_id: u64) -> Vec<u64> {
if self.depth == 0 {
// 0..12
} else {
let parent = self.parent(cell_id, self.depth - 1);
// parent..parent + 4
}
}
fn children(&self, cell_id: u64, depth: u8) -> Vec<u64> {
if self.depth >= depth {
panic!("Child depth must be greater than the current depth, but got {} and {}", depth, self.depth)
} else {
// cell_id << (2 * (depth - self.depth))..(cell_id + 1) << (2 * (depth - self.depth))
}
}
I couldn't quite figure out how to best convert ranges to vec right now, so I'll leave that for when I attempt an implementation.
Did I miss anything? Do you think something like this would make sense to add to this library, or would it be better to have it live elsewhere?
Metadata
Metadata
Assignees
Labels
No labels