#![feature(alloc)]
#![feature(core_intrinsics)]
#![feature(heap_api)]
#![feature(unique)]
use std::cell::Cell;
use std::collections::VecDeque;
use std::collections::vec_deque::Iter as VecDequeIter;
use std::collections::vec_deque::Drain as VecDequeDrain;
use std::marker::PhantomData;
use std::mem::transmute;
use std::ops::{Index, IndexMut};
use std::ptr::null_mut;
mod comprawvec;
mod compvec;
pub use compvec::{CompVec,
Iter as CompVecIter,
IterMut as CompVecIterMut,
VALID_MAX};
#[cfg(target_pointer_width = "32")]
pub const USIZE_BYTES: usize = 4;
#[cfg(target_pointer_width = "64")]
pub const USIZE_BYTES: usize = 8;
pub const WORD_SIZE: usize = USIZE_BYTES * 8;
const BRANCHING_FACTOR_BITS: usize = (0b100 | (USIZE_BYTES >> 2));
const BRANCHING_INDEX_MASK: usize = (1 << BRANCHING_FACTOR_BITS) - 1;
const BRANCHING_DEPTH: usize = (USIZE_BYTES * 8) / BRANCHING_FACTOR_BITS as usize + 1;
fn moving<T>(x: T) -> T {
x
}
pub enum TrieNode<T> {
Interior(CompVec<TrieNode<T>>),
Exterior(CompVec<T>),
}
struct TrieNodePtr<T> {
index: usize,
node: *mut TrieNode<T>,
}
struct PathCache<T> {
index_cache: Option<usize>,
path_cache: [TrieNodePtr<T>; BRANCHING_DEPTH],
}
pub struct Trie<T> {
root: TrieNode<T>,
cache: Cell<*mut PathCache<T>>,
}
pub struct Iter<'a, T: 'a> {
nodes: [*const TrieNode<T>; BRANCHING_DEPTH],
points: [(usize, usize); BRANCHING_DEPTH],
depth: usize,
current: &'a TrieNode<T>,
escape_depth: usize,
index: usize,
}
pub struct IterMut<'a, T: 'a> {
nodes: [*mut TrieNode<T>; BRANCHING_DEPTH],
points: [(usize, usize); BRANCHING_DEPTH],
depth: usize,
current: *mut TrieNode<T>,
escape_depth: usize,
index: usize,
_lifetime: PhantomData<&'a mut T>,
}
pub struct BorrowSync<'a, T: 'a + Send + Sync> {
root: *const TrieNode<T>,
cache: Cell<*mut PathCache<T>>,
_marker: PhantomData<&'a T>,
}
pub struct BorrowShardImmut<'a, T: 'a + Send + Sync> {
buffer: VecDeque<ShardImmut<'a, T>>,
}
pub struct ShardImmut<'a, T: 'a + Send + Sync> {
index: usize,
depth: usize,
node: *const TrieNode<T>,
_marker: PhantomData<&'a T>,
}
pub struct BorrowShardMut<'a, T: 'a + Send> {
buffer: VecDeque<ShardMut<'a, T>>,
}
pub struct ShardMut<'a, T: 'a + Send> {
index: usize,
depth: usize,
node: *mut TrieNode<T>,
_marker: PhantomData<&'a T>,
}
unsafe impl<T: Send> Send for TrieNodePtr<T> {}
unsafe impl<T: Send> Send for PathCache<T> {}
unsafe impl<T: Send> Send for TrieNode<T> {}
unsafe impl<T: Send> Send for Trie<T> {}
unsafe impl<'a, T: 'a + Send> Send for Iter<'a, T> {}
unsafe impl<'a, T: 'a + Send> Send for IterMut<'a, T> {}
unsafe impl<'a, T: 'a + Send + Sync> Send for BorrowSync<'a, T> {}
unsafe impl<'a, T: 'a + Send + Sync> Sync for BorrowSync<'a, T> {}
unsafe impl<'a, T: 'a + Send + Sync> Send for ShardImmut<'a, T> {}
unsafe impl<'a, T: 'a + Send + Sync> Sync for ShardImmut<'a, T> {}
unsafe impl<'a, T: 'a + Send> Send for BorrowShardMut<'a, T> {}
unsafe impl<'a, T: 'a + Send> Send for ShardMut<'a, T> {}
impl<T> TrieNode<T> {
fn new_branch() -> TrieNode<T> {
TrieNode::Interior(CompVec::new())
}
fn new_leaf() -> TrieNode<T> {
TrieNode::Exterior(CompVec::new())
}
fn set(&mut self, index: usize, value: T, depth: usize, cache: &mut PathCache<T>) -> &mut T {
let mut depth = depth;
let mut shift = depth * BRANCHING_FACTOR_BITS;
let mut current = self;
loop {
let local_index = (index >> shift) & BRANCHING_INDEX_MASK;
match moving(current) {
&mut TrieNode::Interior(ref mut branch) => {
let child = branch.get_default_mut(local_index, || {
if depth > 1 {
Self::new_branch()
} else {
Self::new_leaf()
}
});
depth -= 1;
shift -= BRANCHING_FACTOR_BITS;
cache.set(depth, local_index, child);
current = child;
}
&mut TrieNode::Exterior(ref mut leaf) => {
return leaf.set(local_index, value);
}
}
}
}
fn get_default_mut<F>(&mut self,
index: usize,
depth: usize,
default: F,
cache: &mut PathCache<T>)
-> &mut T
where F: Fn() -> T
{
let mut depth = depth;
let mut shift = depth * BRANCHING_FACTOR_BITS;
let mut current = self;
loop {
let local_index = (index >> shift) & BRANCHING_INDEX_MASK;
match moving(current) {
&mut TrieNode::Interior(ref mut branch) => {
let child = branch.get_default_mut(local_index, || {
if depth > 1 {
Self::new_branch()
} else {
Self::new_leaf()
}
});
depth -= 1;
shift -= BRANCHING_FACTOR_BITS;
cache.set(depth, local_index, child);
current = child;
}
&mut TrieNode::Exterior(ref mut leaf) => {
return leaf.get_default_mut(local_index, default);
}
}
}
}
fn get_mut(&mut self, index: usize, depth: usize, cache: &mut PathCache<T>) -> Option<&mut T> {
let mut depth = depth;
let mut shift = depth * BRANCHING_FACTOR_BITS;
let mut current = self;
loop {
let local_index = (index >> shift) & BRANCHING_INDEX_MASK;
match moving(current) {
&mut TrieNode::Interior(ref mut branch) => {
if let Some(child) = branch.get_mut(local_index as usize) {
depth -= 1;
shift -= BRANCHING_FACTOR_BITS;
cache.set(depth, local_index, child);;
current = child;
} else {
cache.invalidate_down(depth);
return None;
}
}
&mut TrieNode::Exterior(ref mut leaf) => return leaf.get_mut(local_index as usize),
}
}
}
fn get(&self, index: usize, depth: usize, cache: &mut PathCache<T>) -> Option<&T> {
let mut depth = depth;
let mut shift = depth * BRANCHING_FACTOR_BITS;
let mut current = self;
loop {
let local_index = (index >> shift) & BRANCHING_INDEX_MASK;
match moving(current) {
&TrieNode::Interior(ref branch) => {
if let Some(child) = branch.get(local_index as usize) {
depth -= 1;
shift -= BRANCHING_FACTOR_BITS;
cache.set(depth, local_index, child);;
current = child;
} else {
cache.invalidate_down(depth);
return None;
}
}
&TrieNode::Exterior(ref leaf) => return leaf.get(local_index as usize),
}
}
}
fn remove(&mut self,
index: usize,
depth: usize,
cache: &mut PathCache<T>)
-> (Option<T>, bool) {
match self {
&mut TrieNode::Interior(ref mut branch) => {
let shift = depth * BRANCHING_FACTOR_BITS;
let local_index = (index >> shift) & BRANCHING_INDEX_MASK;
let (value, empty_child) = {
let mut maybe_child = branch.get_mut(local_index as usize);
if let Some(ref mut child) = maybe_child {
child.remove(index, depth - 1, cache)
} else {
(None, false)
}
};
if empty_child {
branch.remove(local_index as usize);
cache.invalidate(depth);
}
(value, branch.is_empty())
}
&mut TrieNode::Exterior(ref mut leaf) => {
let local_index = index & BRANCHING_INDEX_MASK;
let value = leaf.remove(local_index as usize);
cache.invalidate(depth);
(value, leaf.is_empty())
}
}
}
fn retain_if<F>(&mut self, index: usize, depth: usize, f: &mut F) -> bool
where F: FnMut(usize, &mut T) -> bool
{
match self {
&mut TrieNode::Interior(ref mut int_vec) => {
let shift = depth * BRANCHING_FACTOR_BITS;
let mut masked_valid = VALID_MAX;
let mut compressed = 0;
loop {
let (do_remove, local_index, next_masked_valid, next_compressed) = {
if let Some(((v, c), (i, ref mut child))) = int_vec.next_mut(masked_valid,
compressed) {
let index = index | (i << shift);
(child.retain_if(index, depth - 1, f), i, v, c)
} else {
break;
}
};
if do_remove {
int_vec.remove(local_index as usize);
} else {
compressed = next_compressed; }
masked_valid = next_masked_valid;
}
int_vec.is_empty()
}
&mut TrieNode::Exterior(ref mut ext_vec) => {
let mut masked_valid = VALID_MAX;
let mut compressed = 0;
loop {
let (do_remove, local_index, next_masked_valid, next_compressed) = {
if let Some(((v, c), (i, ref mut value))) = ext_vec.next_mut(masked_valid,
compressed) {
let index = index | i;
(!f(index, value), i, v, c)
} else {
break;
}
};
if do_remove {
ext_vec.remove(local_index as usize);
} else {
compressed = next_compressed;
}
masked_valid = next_masked_valid;
}
ext_vec.is_empty()
}
}
}
}
impl<T> TrieNodePtr<T> {
fn set(&mut self, index: usize, node: &TrieNode<T>) {
self.index = index;
self.node = unsafe { transmute(node) };
}
fn is_hit(&self, index: usize) -> bool {
(self.index == index) && (!self.node.is_null())
}
fn get(&self) -> *const TrieNode<T> {
self.node
}
fn get_mut(&self) -> *mut TrieNode<T> {
self.node
}
fn invalidate(&mut self) {
self.node = null_mut();
}
}
impl<T> Clone for TrieNodePtr<T> {
fn clone(&self) -> TrieNodePtr<T> {
TrieNodePtr {
index: self.index,
node: self.node,
}
}
}
impl<T> Copy for TrieNodePtr<T> {}
impl<T> Default for TrieNodePtr<T> {
fn default() -> TrieNodePtr<T> {
TrieNodePtr {
index: 0,
node: null_mut(),
}
}
}
impl<T> PathCache<T> {
fn new() -> PathCache<T> {
PathCache {
index_cache: None,
path_cache: [TrieNodePtr::<T>::default(); BRANCHING_DEPTH],
}
}
fn get_start(&mut self, index: usize) -> u8 {
let depth = if let Some(last_index) = self.index_cache {
let diff = WORD_SIZE - (index ^ last_index).leading_zeros() as usize;
(diff / BRANCHING_FACTOR_BITS) + if diff % BRANCHING_FACTOR_BITS > 0 { 1 } else { 0 }
} else {
BRANCHING_DEPTH
};
self.index_cache = Some(index);
depth as u8
}
fn set(&mut self, depth: usize, index: usize, node: &TrieNode<T>) {
self.path_cache[depth].set(index, node);
}
fn invalidate(&mut self, depth: usize) {
self.path_cache[depth].invalidate();
}
fn invalidate_all(&mut self) {
for d in 0..BRANCHING_DEPTH {
self.path_cache[d].invalidate();
}
}
fn invalidate_down(&mut self, depth: usize) {
for d in 0..(depth + 1) {
self.path_cache[d].invalidate();
}
}
fn get_node(&mut self, index: usize) -> Option<(*const TrieNode<T>, u8)> {
let mut cached_depth = self.get_start(index);
while cached_depth < (BRANCHING_DEPTH as u8 - 1) {
let parent_shift = (cached_depth + 1) * BRANCHING_FACTOR_BITS as u8;
let parent_index = (index >> parent_shift) & BRANCHING_INDEX_MASK;
let cache = &self.path_cache[cached_depth as usize];
if cache.is_hit(parent_index) {
return Some((cache.get(), cached_depth));
}
cached_depth += 1;
}
None
}
fn get_node_mut(&mut self, index: usize) -> Option<(*mut TrieNode<T>, u8)> {
let mut cached_depth = self.get_start(index);
while cached_depth < (BRANCHING_DEPTH as u8 - 1) {
let parent_shift = (cached_depth + 1) * BRANCHING_FACTOR_BITS as u8;
let parent_index = (index >> parent_shift) & BRANCHING_INDEX_MASK;
let cache = &self.path_cache[cached_depth as usize];
if cache.is_hit(parent_index) {
return Some((cache.get_mut(), cached_depth));
}
cached_depth += 1;
}
None
}
}
impl<T> Clone for PathCache<T> {
fn clone(&self) -> PathCache<T> {
PathCache {
index_cache: self.index_cache,
path_cache: self.path_cache.clone(),
}
}
}
impl<T> Copy for PathCache<T> {}
impl<T> Trie<T> {
pub fn new() -> Trie<T> {
let root = TrieNode::new_branch();
let cache = Box::into_raw(Box::new(PathCache::new()));
Trie {
root: root,
cache: Cell::new(cache),
}
}
pub fn set(&mut self, index: usize, value: T) -> &mut T {
let cache = unsafe { &mut *self.cache.get() };
if let Some((start_node, depth)) = cache.get_node_mut(index) {
unsafe { &mut *start_node }.set(index, value, depth as usize, cache)
} else {
self.root.set(index, value, BRANCHING_DEPTH - 1, cache)
}
}
pub fn get_default_mut<F>(&mut self, index: usize, default: F) -> &mut T
where F: Fn() -> T
{
let cache = unsafe { &mut *self.cache.get() };
if let Some((start_node, depth)) = cache.get_node_mut(index) {
unsafe { &mut *start_node }.get_default_mut(index, depth as usize, default, cache)
} else {
self.root.get_default_mut(index, BRANCHING_DEPTH - 1, default, cache)
}
}
pub fn get_mut(&mut self, index: usize) -> Option<&mut T> {
let cache = unsafe { &mut *self.cache.get() };
if let Some((start_node, depth)) = cache.get_node_mut(index) {
unsafe { &mut *start_node }.get_mut(index, depth as usize, cache)
} else {
self.root.get_mut(index, BRANCHING_DEPTH - 1, cache)
}
}
pub fn get(&self, index: usize) -> Option<&T> {
let cache = unsafe { &mut *self.cache.get() };
if let Some((start_node, depth)) = cache.get_node(index) {
unsafe { &*start_node }.get(index, depth as usize, cache)
} else {
self.root.get(index, BRANCHING_DEPTH - 1, cache)
}
}
pub fn remove(&mut self, index: usize) -> Option<T> {
let cache = unsafe { &mut *self.cache.get() };
if let (Some(value), _) = if let Some((start_node, depth)) = cache.get_node_mut(index) {
unsafe { &mut *start_node }.remove(index, depth as usize, cache)
} else {
self.root.remove(index, BRANCHING_DEPTH - 1, cache)
} {
Some(value)
} else {
None
}
}
pub fn retain_if<F>(&mut self, mut f: F)
where F: FnMut(usize, &mut T) -> bool
{
unsafe { &mut *self.cache.get() }.invalidate_all();
self.root.retain_if(0usize, BRANCHING_DEPTH - 1, &mut f);
}
pub fn iter(&self) -> Iter<T> {
Iter::new(&self.root, BRANCHING_DEPTH, 0)
}
pub fn iter_mut(&mut self) -> IterMut<T> {
IterMut::new(&mut self.root, BRANCHING_DEPTH, 0)
}
}
impl<T: Send> Trie<T> {
pub fn borrow_sharded(&mut self, n: usize) -> BorrowShardMut<T> {
unsafe { &mut *self.cache.get() }.invalidate_all();
BorrowShardMut::new(&mut self.root, n)
}
pub fn prune(&mut self) {
self.retain_if(|_, _| true);
}
}
impl<T: Send + Sync> Trie<T> {
pub fn borrow_sync(&self) -> BorrowSync<T> {
BorrowSync::new(&self.root)
}
}
impl<T> Drop for Trie<T> {
fn drop(&mut self) {
unsafe { Box::from_raw(self.cache.get()) };
}
}
impl<T> Index<usize> for Trie<T> {
type Output = T;
fn index(&self, index: usize) -> &T {
self.get(index).unwrap()
}
}
impl<T> IndexMut<usize> for Trie<T> {
fn index_mut(&mut self, index: usize) -> &mut T {
self.get_mut(index).unwrap()
}
}
impl<'a, T> Iter<'a, T> {
pub fn new(root: &TrieNode<T>, escape_depth: usize, base_index: usize) -> Iter<T> {
Iter {
nodes: [null_mut(); BRANCHING_DEPTH],
points: [(VALID_MAX, 0); BRANCHING_DEPTH],
depth: escape_depth - 1,
escape_depth: escape_depth,
current: root,
index: base_index,
}
}
}
impl<'a, T> Iterator for Iter<'a, T> {
type Item = (usize, &'a T);
fn next(&mut self) -> Option<(usize, &'a T)> {
loop {
match self.current {
&TrieNode::Interior(ref node) => {
let point = self.points[self.depth];
if let Some(((mask, comp), (index_part, child))) = node.next(point.0, point.1) {
self.points[self.depth] = (mask, comp);
let shift = self.depth * BRANCHING_FACTOR_BITS;
let index_mask = !(BRANCHING_INDEX_MASK << shift);
self.index &= index_mask;
self.index |= index_part << shift;
self.nodes[self.depth] = self.current;
self.current = child;
self.depth -= 1;
} else {
self.points[self.depth] = (VALID_MAX, 0usize);
self.depth += 1;
if self.depth == self.escape_depth {
return None;
}
self.current = unsafe { &*self.nodes[self.depth] };
}
}
&TrieNode::Exterior(ref node) => {
let point = self.points[0];
if let Some(((mask, comp), (index_part, value))) = node.next(point.0, point.1) {
self.points[0] = (mask, comp);
let index_mask = !BRANCHING_INDEX_MASK;
self.index = self.index & index_mask | index_part;
return Some((self.index, value));
} else {
self.points[0] = (VALID_MAX, 0usize);
self.depth = 1;
self.current = unsafe { &*self.nodes[1] };
}
}
}
}
}
}
impl<'a, T> IterMut<'a, T> {
pub fn new(root: &mut TrieNode<T>, escape_depth: usize, base_index: usize) -> IterMut<T> {
IterMut {
nodes: [null_mut(); BRANCHING_DEPTH],
points: [(VALID_MAX, 0); BRANCHING_DEPTH],
depth: escape_depth - 1,
escape_depth: escape_depth,
current: root,
index: base_index,
_lifetime: PhantomData,
}
}
}
impl<'a, T> Iterator for IterMut<'a, T> {
type Item = (usize, &'a mut T);
fn next(&mut self) -> Option<Self::Item> {
loop {
match unsafe { &mut *self.current } {
&mut TrieNode::Interior(ref mut node) => {
let point = self.points[self.depth];
if let Some(((mask, comp), (index_part, child))) = node.next_mut(point.0,
point.1) {
self.points[self.depth] = (mask, comp);
let shift = self.depth * BRANCHING_FACTOR_BITS;
let index_mask = !(BRANCHING_INDEX_MASK << shift);
self.index &= index_mask;
self.index |= index_part << shift;
self.nodes[self.depth] = self.current;
self.current = child;
self.depth -= 1;
} else {
self.points[self.depth] = (VALID_MAX, 0usize);
self.depth += 1;
if self.depth == self.escape_depth {
return None;
}
self.current = unsafe { &mut *self.nodes[self.depth] };
}
}
&mut TrieNode::Exterior(ref mut node) => {
let point = self.points[0];
if let Some(((mask, comp), (index_part, value))) = node.next_mut(point.0,
point.1) {
self.points[0] = (mask, comp);
let index_mask = !BRANCHING_INDEX_MASK;
self.index = self.index & index_mask | index_part;
return Some((self.index, value));
} else {
self.points[0] = (VALID_MAX, 0usize);
self.depth = 1;
self.current = unsafe { &mut *self.nodes[1] };
}
}
}
}
}
}
impl<'a, T: Send + Sync> BorrowSync<'a, T> {
fn new(root: &'a TrieNode<T>) -> BorrowSync<'a, T> {
let cache = Box::into_raw(Box::new(PathCache::new()));
BorrowSync {
root: root,
cache: Cell::new(cache),
_marker: PhantomData
}
}
pub fn get(&self, index: usize) -> Option<&'a T> {
let cache = unsafe { &mut *self.cache.get() };
if let Some((start_node, depth)) = cache.get_node(index) {
unsafe { &*start_node }.get(index, depth as usize, cache)
} else {
unsafe { &*self.root }.get(index, BRANCHING_DEPTH - 1, cache)
}
}
pub fn borrow_sharded(&self, n: usize) -> BorrowShardImmut<'a, T> {
BorrowShardImmut::new(unsafe { &*self.root }, n)
}
}
impl<'a, T: Send + Sync> Clone for BorrowSync<'a, T> {
fn clone(&self) -> BorrowSync<'a, T> {
let cache = Box::into_raw(Box::new(PathCache::new()));
BorrowSync {
root: self.root,
cache: Cell::new(cache),
_marker: PhantomData
}
}
}
impl<'a, T: Send + Sync> Drop for BorrowSync<'a, T> {
fn drop(&mut self) {
unsafe { Box::from_raw(self.cache.get()) };
}
}
impl<'a, T: 'a + Send + Sync> BorrowShardImmut<'a, T> {
fn new(root: &'a TrieNode<T>, n: usize) -> BorrowShardImmut<'a, T> {
let mut depth = BRANCHING_DEPTH - 1;
let mut buf = VecDeque::with_capacity(WORD_SIZE);
buf.push_back(ShardImmut::new(0, depth, root));
loop {
if let Some(subtrie) = buf.pop_front() {
if (subtrie.depth < depth && buf.len() >= n) ||
subtrie.depth == 2 {
buf.push_front(subtrie);
break;
}
depth = subtrie.depth;
if let &TrieNode::Interior(ref int_vec) = unsafe { &*subtrie.node } {
for child in int_vec.iter() {
let index = subtrie.index | child.0 << (depth * BRANCHING_FACTOR_BITS);
buf.push_back(ShardImmut::new(index, subtrie.depth - 1, child.1));
}
} else {
unreachable!();
}
} else {
break;
}
}
BorrowShardImmut {
buffer: buf
}
}
pub fn iter(&'a self) -> VecDequeIter<'a, ShardImmut<'a, T>> {
self.buffer.iter()
}
}
impl<'a, T: 'a + Send + Sync> ShardImmut<'a, T> {
fn new(index: usize, depth: usize, node: *const TrieNode<T>) -> ShardImmut<'a, T> {
ShardImmut {
index: index,
depth: depth,
node: node,
_marker: PhantomData
}
}
pub fn iter(&self) -> Iter<T> {
Iter::new(unsafe { &*self.node }, self.depth + 1, self.index)
}
}
impl<'a, T: 'a + Send> BorrowShardMut<'a, T> {
fn new(root: &'a mut TrieNode<T>, n: usize) -> BorrowShardMut<'a, T> {
let mut depth = BRANCHING_DEPTH - 1;
let mut buf = VecDeque::with_capacity(WORD_SIZE);
buf.push_back(ShardMut::new(0, depth, root));
loop {
if let Some(subtrie) = buf.pop_front() {
if (subtrie.depth < depth && buf.len() >= n) ||
subtrie.depth == 2 {
buf.push_front(subtrie);
break;
}
depth = subtrie.depth;
if let &mut TrieNode::Interior(ref mut int_vec) = unsafe { &mut *subtrie.node } {
for child in int_vec.iter_mut() {
let index = subtrie.index | child.0 << (depth * BRANCHING_FACTOR_BITS);
buf.push_back(ShardMut::new(index, subtrie.depth - 1, child.1));
}
} else {
unreachable!();
}
} else {
break;
}
}
BorrowShardMut {
buffer: buf
}
}
pub fn drain(&'a mut self) -> VecDequeDrain<'a, ShardMut<'a, T>> {
self.buffer.drain(..)
}
}
impl<'a, T: 'a + Send> ShardMut<'a, T> {
fn new(index: usize, depth: usize, node: *mut TrieNode<T>) -> ShardMut<'a, T> {
ShardMut {
index: index,
depth: depth,
node: node,
_marker: PhantomData
}
}
pub fn iter(&self) -> Iter<T> {
Iter::new(unsafe { &*self.node }, self.depth + 1, self.index)
}
pub fn iter_mut(&mut self) -> IterMut<T> {
IterMut::new(unsafe { &mut *self.node }, self.depth + 1, self.index)
}
pub fn retain_if<F>(&mut self, mut f: F)
where F: FnMut(usize, &mut T) -> bool
{
unsafe { &mut *self.node }.retain_if(self.index, self.depth, &mut f);
}
}