2022-08-09 13:25:24 +00:00
|
|
|
pub(self) use bumpalo::boxed::Box as BumpBox;
|
2022-08-05 10:47:51 +00:00
|
|
|
pub(self) use bumpalo::collections::vec::Vec as BumpVec;
|
2022-08-05 12:04:49 +00:00
|
|
|
use owning_ref::OwningRefMut;
|
2022-08-05 10:47:51 +00:00
|
|
|
use std::marker::{PhantomData, PhantomPinned};
|
|
|
|
|
2022-08-10 07:41:21 +00:00
|
|
|
use crate::{HasLength, Rle};
|
2022-08-05 10:47:51 +00:00
|
|
|
use bumpalo::Bump;
|
|
|
|
use tree_trait::RleTreeTrait;
|
|
|
|
|
|
|
|
use self::node::{InternalNode, Node};
|
|
|
|
|
2022-08-09 13:25:24 +00:00
|
|
|
mod fixed_size_vec;
|
2022-08-10 07:41:21 +00:00
|
|
|
mod iter;
|
2022-08-05 10:47:51 +00:00
|
|
|
mod node;
|
2022-08-10 07:41:21 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod test;
|
2022-08-05 10:47:51 +00:00
|
|
|
mod tree_trait;
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2022-08-05 12:04:49 +00:00
|
|
|
pub struct RleTreeRaw<'a, T: Rle, A: RleTreeTrait<T>> {
|
2022-08-05 10:47:51 +00:00
|
|
|
bump: &'a Bump,
|
|
|
|
node: Node<'a, T, A>,
|
|
|
|
_pin: PhantomPinned,
|
|
|
|
_a: PhantomData<(A, T)>,
|
|
|
|
}
|
|
|
|
|
2022-08-05 12:04:49 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
type TreeRef<T, A> =
|
|
|
|
OwningRefMut<Box<(Box<Bump>, RleTreeRaw<'static, T, A>)>, RleTreeRaw<'static, T, A>>;
|
|
|
|
|
2022-08-09 13:25:24 +00:00
|
|
|
pub struct RleTree<T: Rle + 'static, A: RleTreeTrait<T> + 'static> {
|
2022-08-05 12:04:49 +00:00
|
|
|
tree: TreeRef<T, A>,
|
|
|
|
}
|
|
|
|
|
2022-08-09 13:25:24 +00:00
|
|
|
impl<T: Rle + 'static, A: RleTreeTrait<T> + 'static> RleTree<T, A> {
|
2022-08-05 12:04:49 +00:00
|
|
|
pub fn new() -> Self {
|
|
|
|
let bump = Box::new(Bump::new());
|
|
|
|
let tree = RleTreeRaw::new(unsafe { &*(&*bump as *const _) });
|
|
|
|
let m = OwningRefMut::new(Box::new((bump, tree)));
|
|
|
|
let tree = m.map_mut(|(_, tree)| tree);
|
|
|
|
Self { tree }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_ref(&self) -> &RleTreeRaw<'static, T, A> {
|
|
|
|
self.tree.as_ref()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_mut(&mut self) -> &mut RleTreeRaw<'static, T, A> {
|
|
|
|
self.tree.as_mut()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, T: Rle, A: RleTreeTrait<T>> RleTreeRaw<'a, T, A> {
|
|
|
|
#[inline]
|
|
|
|
fn new(bump: &'a Bump) -> Self {
|
2022-08-05 10:47:51 +00:00
|
|
|
Self {
|
|
|
|
bump,
|
2022-08-09 13:25:24 +00:00
|
|
|
node: Node::Internal(BumpBox::new_in(InternalNode::new(bump, None), bump)),
|
2022-08-05 10:47:51 +00:00
|
|
|
_pin: PhantomPinned,
|
|
|
|
_a: PhantomData,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-09 13:25:24 +00:00
|
|
|
#[inline]
|
|
|
|
pub fn insert(&mut self, index: A::Int, value: T) {
|
|
|
|
match self.node {
|
|
|
|
Node::Internal(ref mut node) => {
|
|
|
|
node.insert(index, value);
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
unreachable!()
|
|
|
|
}
|
|
|
|
}
|
2022-08-05 10:47:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// return a cursor to the tree
|
2022-08-09 13:25:24 +00:00
|
|
|
pub fn get(&self, index: A::Int) {
|
2022-08-05 10:47:51 +00:00
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
|
2022-08-10 07:41:21 +00:00
|
|
|
pub fn iter(&self) -> iter::Iter<'_, 'a, T, A> {
|
|
|
|
iter::Iter::new(self.node.get_first_leaf())
|
2022-08-05 10:47:51 +00:00
|
|
|
}
|
|
|
|
|
2022-08-09 13:25:24 +00:00
|
|
|
pub fn delete_range(&mut self, from: A::Int, to: A::Int) {
|
2022-08-05 10:47:51 +00:00
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
|
2022-08-09 13:25:24 +00:00
|
|
|
pub fn iter_range(&self, from: A::Int, to: A::Int) {
|
2022-08-05 10:47:51 +00:00
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
fn debug_check(&self) {
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|
2022-08-05 12:04:49 +00:00
|
|
|
|
2022-08-10 07:41:21 +00:00
|
|
|
impl<'a, T: Rle, A: RleTreeTrait<T>> HasLength for RleTreeRaw<'a, T, A> {
|
|
|
|
fn len(&self) -> usize {
|
|
|
|
self.node.len()
|
2022-08-05 12:04:49 +00:00
|
|
|
}
|
|
|
|
}
|