refactor: refine style

This commit is contained in:
Zixuan Chen 2022-08-12 11:52:00 +08:00
parent 4009bc0079
commit 34632f61c3
4 changed files with 10 additions and 13 deletions

View file

@ -14,13 +14,11 @@ mod tree_trait;
#[derive(Debug)]
pub struct RleTreeRaw<'a, T: Rle, A: RleTreeTrait<T>> {
bump: &'a Bump,
node: Node<'a, T, A>,
_pin: PhantomPinned,
_a: PhantomData<(A, T)>,
}
#[allow(unused)]
type TreeRef<T, A> =
OwningRefMut<Box<(Box<Bump>, RleTreeRaw<'static, T, A>)>, RleTreeRaw<'static, T, A>>;
@ -56,7 +54,6 @@ impl<'a, T: Rle, A: RleTreeTrait<T>> RleTreeRaw<'a, T, A> {
#[inline]
fn new(bump: &'a Bump) -> Self {
Self {
bump,
node: Node::Internal(BumpBox::new_in(InternalNode::new(bump, None), bump)),
_pin: PhantomPinned,
_a: PhantomData,

View file

@ -46,8 +46,8 @@ pub(crate) enum Either {
impl<'a, T: Rle, A: RleTreeTrait<T>> Node<'a, T, A> {
#[inline]
fn new_internal(bump: &'a Bump) -> Self {
Self::Internal(BumpBox::new_in(InternalNode::new(bump, None), bump))
fn _new_internal(bump: &'a Bump, parent: Option<NonNull<InternalNode<'a, T, A>>>) -> Self {
Self::Internal(BumpBox::new_in(InternalNode::new(bump, parent), bump))
}
#[inline]

View file

@ -54,7 +54,7 @@ impl<'a, T: Rle, A: RleTreeTrait<T>> InternalNode<'a, T, A> {
#[cfg(test)]
pub(crate) fn check(&mut self) {
if self.parent.is_some() {
if self.is_root() {
assert!(
self.children.len() >= A::MIN_CHILDREN_NUM,
"children.len() = {}",
@ -210,7 +210,7 @@ impl<'a, T: Rle, A: RleTreeTrait<T>> InternalNode<'a, T, A> {
Err(mut new) => {
A::update_cache_internal(self);
A::update_cache_internal(&mut new);
if self.parent.is_none() {
if self.is_root() {
self._create_level(new);
Ok(())
} else {
@ -222,7 +222,7 @@ impl<'a, T: Rle, A: RleTreeTrait<T>> InternalNode<'a, T, A> {
/// root node function. assume self and new's caches are up-to-date
fn _create_level(&mut self, mut new: BumpBox<'a, InternalNode<'a, T, A>>) {
debug_assert!(self.parent.is_none());
debug_assert!(self.is_root());
let mut left = BumpBox::new_in(InternalNode::new(self.bump, None), self.bump);
std::mem::swap(&mut *left, self);
let left_ptr = (&mut *left).into();
@ -238,8 +238,8 @@ impl<'a, T: Rle, A: RleTreeTrait<T>> InternalNode<'a, T, A> {
}
fn _insert(&mut self, index: A::Int, value: T) -> Result<(), BumpBox<'a, Self>> {
if self.children.len() == 0 {
debug_assert!(self.parent.is_none());
if self.children.is_empty() {
debug_assert!(self.is_root());
let ptr = NonNull::new(self as *mut _).unwrap();
self.children.push(Node::new_leaf(self.bump, ptr));
}
@ -286,7 +286,7 @@ impl<'a, T: Rle, A: RleTreeTrait<T>> InternalNode<'a, T, A> {
/// this can only invoke from root
#[inline]
pub(crate) fn delete(&mut self, start: Option<A::Int>, end: Option<A::Int>) {
assert!(self.parent.is_none());
debug_assert!(self.is_root());
let mut visited = Vec::new();
match self._delete(start, end, &mut visited, 1) {
Ok(_) => {

View file

@ -35,7 +35,7 @@ impl<'a, T: Rle, A: RleTreeTrait<T>> LeafNode<'a, T, A> {
}
pub fn push_child(&mut self, value: T) -> Result<(), BumpBox<'a, Self>> {
if self.children.len() > 0 {
if !self.children.is_empty() {
let last = self.children.last_mut().unwrap();
if last.is_mergable(&value, &()) {
last.merge(&value, &());
@ -99,7 +99,7 @@ impl<'a, T: Rle, A: RleTreeTrait<T>> LeafNode<'a, T, A> {
}
fn _insert(&mut self, raw_index: A::Int, value: T) -> Result<(), BumpBox<'a, Self>> {
if self.children.len() == 0 {
if self.children.is_empty() {
self.children.push(value);
return Ok(());
}