diff --git a/crates/rle/src/range_map.rs b/crates/rle/src/range_map.rs index 278b474e..2d7d3a19 100644 --- a/crates/rle/src/range_map.rs +++ b/crates/rle/src/range_map.rs @@ -104,6 +104,44 @@ impl RangeMap } } +pub struct WithStartEnd { + start: Index, + end: Index, + value: T, +} + +impl Sliceable for WithStartEnd { + fn slice(&self, from: usize, to: usize) -> Self { + Self { + start: self.start + Index::from_usize(from).unwrap(), + end: Index::min(self.end, self.start + Index::from_usize(to).unwrap()), + value: self.value.clone(), + } + } +} + +impl HasLength for WithStartEnd { + fn len(&self) -> usize { + Index::as_(self.end - self.start) + } +} + +impl Mergable for WithStartEnd { + fn is_mergable(&self, other: &Self, _conf: &()) -> bool + where + Self: Sized, + { + self.end == other.start && self.value == other.value + } + + fn merge(&mut self, other: &Self, _conf: &()) + where + Self: Sized, + { + self.end = other.end; + } +} + #[cfg(test)] mod test { use super::*; diff --git a/crates/rle/src/rle_tree.rs b/crates/rle/src/rle_tree.rs index 173d7b92..9cfd1403 100644 --- a/crates/rle/src/rle_tree.rs +++ b/crates/rle/src/rle_tree.rs @@ -10,7 +10,6 @@ use tree_trait::RleTreeTrait; mod cursor; pub mod iter; pub mod node; -pub mod nonnull; #[cfg(test)] mod test; pub mod tree_trait; diff --git a/crates/rle/src/rle_tree/nonnull.rs b/crates/rle/src/rle_tree/nonnull.rs deleted file mode 100644 index e21d5d7d..00000000 --- a/crates/rle/src/rle_tree/nonnull.rs +++ /dev/null @@ -1,31 +0,0 @@ -use std::ptr::NonNull; - -use crate::{HasLength, Mergable, Sliceable}; - -impl Mergable for NonNull { - fn is_mergable(&self, _other: &Self, _conf: &()) -> bool - where - Self: Sized, - { - false - } - - fn merge(&mut self, _other: &Self, _conf: &()) - where - Self: Sized, - { - unreachable!() - } -} - -impl Sliceable for NonNull { - fn slice(&self, _from: usize, _to: usize) -> Self { - *self - } -} - -impl HasLength for NonNull { - fn len(&self) -> usize { - 1 - } -} diff --git a/crates/rle/src/rle_tree/test/notify_test.rs b/crates/rle/src/rle_tree/test/notify_test.rs index 2975680d..4b3857a5 100644 --- a/crates/rle/src/rle_tree/test/notify_test.rs +++ b/crates/rle/src/rle_tree/test/notify_test.rs @@ -30,15 +30,15 @@ impl Interaction { } fn test(tree: &mut RleTree, RangeTreeTrait>, interactions: &[Interaction]) { - let mut range_map: RangeMap, RangeTreeTrait>>> = - Default::default(); - let mut func = |range: &Range, node: *mut LeafNode<'_, Range, RangeTreeTrait>| { - let ptr = unsafe { NonNull::new_unchecked(node as usize as *mut _) }; - range_map.set(range.start, ptr); - }; - for interaction in interactions.iter() { - interaction.apply(tree, &mut func); - } + // let mut range_map: RangeMap, RangeTreeTrait>>> = + // Default::default(); + // let mut func = |range: &Range, node: *mut LeafNode<'_, Range, RangeTreeTrait>| { + // let ptr = unsafe { NonNull::new_unchecked(node as usize as *mut _) }; + // range_map.set(range.start, ptr); + // }; + // for interaction in interactions.iter() { + // interaction.apply(tree, &mut func); + // } } prop_compose! {