chore: delete init

This commit is contained in:
Zixuan Chen 2022-10-10 17:36:55 +08:00
parent 944d60bfe9
commit af63cd6a9c
5 changed files with 48 additions and 15 deletions

View file

@ -1,4 +1,4 @@
use rle::HasLength;
use rle::{HasLength, RleVec};
use crate::{
container::text::tracker::yata::YataImpl,
@ -11,7 +11,7 @@ use crate::{
use self::{
content_map::ContentMap,
cursor_map::{make_notify, CursorMap},
y_span::{Status, YSpan},
y_span::{Status, StatusChange, YSpan},
};
use super::text_content::TextOpContent;
@ -96,11 +96,10 @@ impl Tracker {
// SAFETY: we know this is safe because in [YataImpl::insert_after] there is no access to shared elements
unsafe { crdt_list::yata::integrate::<YataImpl>(self, yspan) };
}
TextOpContent::Delete {
id: _,
pos: _,
len: _,
} => todo!(),
TextOpContent::Delete { id, pos, len } => {
let spans = self.content.get_id_spans(*pos, *len);
todo!()
}
}
}
}
@ -108,6 +107,17 @@ impl Tracker {
crate::op::OpContent::Redo { .. } => todo!(),
}
}
pub fn update_spans(&mut self, spans: &RleVec<IdSpan>, change: StatusChange) {
for span in spans.iter() {
for marker in self
.id_to_cursor
.get_range(span.min_id().into(), span.max_id().into())
{
todo!()
}
}
}
}
impl Default for Tracker {

View file

@ -50,18 +50,28 @@ impl Marker {
}
}
pub fn as_cursor_mut(
/// # Safety
///
/// It's safe when you are sure that the returned cursor is the only reference to the target yspan tree
pub unsafe fn as_cursor_mut(
&mut self,
id: ID,
) -> Option<SafeCursorMut<'static, YSpan, YSpanTreeTrait>> {
match self {
Marker::Insert { ptr, len: _ } => {
// SAFETY: tree data is always valid
let node = unsafe { ptr.as_ref() };
let node = ptr.as_ref();
debug_assert!(!node.is_deleted());
let position = node.children().iter().position(|x| x.contain_id(id))?;
// SAFETY: we just checked it is valid
Some(unsafe { SafeCursorMut::new(*ptr, position, 0, Position::Start, self.len()) })
let child = &node.children()[position];
let start_counter = child.id.counter;
let offset = id.counter - start_counter;
Some(SafeCursorMut::new(
*ptr,
position,
offset as usize,
Position::from_offset(offset as isize, child.len()),
0,
))
}
Marker::Delete(_) => None,
}

View file

@ -1,4 +1,4 @@
use crate::id::{ClientID, Counter};
use crate::id::{ClientID, Counter, ID};
use rle::{HasLength, Mergable, Slice, Sliceable};
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
@ -103,14 +103,24 @@ impl IdSpan {
}
#[inline]
pub fn min(&self) -> Counter {
pub fn min_ctr(&self) -> Counter {
self.counter.min()
}
#[inline]
pub fn max(&self) -> Counter {
pub fn max_ctr(&self) -> Counter {
self.counter.max()
}
#[inline]
pub fn min_id(&self) -> ID {
ID::new(self.client_id, self.counter.min())
}
#[inline]
pub fn max_id(&self) -> ID {
ID::new(self.client_id, self.counter.max())
}
}
impl HasLength for IdSpan {

View file

@ -96,6 +96,7 @@ impl<T: Rle, A: RleTreeTrait<T>> RleTree<T, A> {
}
/// return the first valid cursor after the given index
/// reviewed by @Leeeon233
#[inline]
fn get_cursor_ge(&self, mut index: A::Int) -> Option<SafeCursor<'_, T, A>> {
self.with_node(|mut node| {
@ -204,6 +205,7 @@ impl<T: Rle, A: RleTreeTrait<T>> RleTree<T, A> {
})
}
/// reviewed by @Leeeon233
pub fn iter_range(&self, start: A::Int, end: Option<A::Int>) -> iter::Iter<'_, T, A> {
let cursor_from = self.get_cursor_ge(start);
if cursor_from.is_none() {

View file

@ -10,6 +10,7 @@ pub struct UnsafeCursor<'tree, T: Rle, A: RleTreeTrait<T>> {
pub leaf: NonNull<LeafNode<'tree, T, A>>,
pub index: usize,
pub offset: usize,
// TODO: considering remove this field, use a getter function instead
pub pos: Position,
pub len: usize,
_phantom: PhantomData<&'tree usize>,