fix: crdt-list yata integrate err

This commit is contained in:
Zixuan Chen 2022-10-12 11:31:07 +08:00
parent 90596fa3e3
commit 4213d4c488
3 changed files with 33 additions and 93 deletions

View file

@ -140,6 +140,15 @@ impl Yata for YataImpl {
let mut notify = make_notify(&mut container.id_to_cursor); let mut notify = make_notify(&mut container.id_to_cursor);
anchor.insert_after_notify(op, &mut notify) anchor.insert_after_notify(op, &mut notify)
} }
fn insert_immediately_after(
container: &mut Self::Container,
anchor: Self::Cursor<'_>,
op: Self::OpUnit,
) {
let mut notify = make_notify(&mut container.id_to_cursor);
anchor.insert_shift_notify(op, 1, &mut notify)
}
} }
#[cfg(test)] #[cfg(test)]
@ -299,102 +308,25 @@ pub mod fuzz {
#[test] #[test]
fn issue_1() { fn issue_1() {
crdt_list::test::test_with_actions::<YataImpl>( crdt_list::test::test_with_actions::<YataImpl>(
5, 3,
&[ &[
NewOp { Delete {
client_id: 11719107999768421014, client_id: 1,
pos: 11719107999768421026, pos: 0,
len: 1,
}, },
Delete { Delete {
client_id: 10851025925718409122, client_id: 0,
pos: 531712649396118, pos: 1,
len: 18446504380166307839, len: 1,
},
Delete {
client_id: 10880696699727118335,
pos: 18374967954648334335,
len: 18446744069414584321,
},
Delete {
client_id: 11719210655348162559,
pos: 18446641418129810082,
len: 10873349650923257855,
},
Delete {
client_id: 11719107999768421119,
pos: 11719107999768421026,
len: 11719107999768421026,
}, },
NewOp { NewOp {
client_id: 16835197176461304482, client_id: 1,
pos: 11719107999768421026, pos: 1,
}, },
NewOp { NewOp {
client_id: 11719107999768421026, client_id: 0,
pos: 10851025927479993010, pos: 1,
},
NewOp {
client_id: 9223370937374840575,
pos: 18446744073695264767,
},
Delete {
client_id: 18446743622737985535,
pos: 2194745065471,
len: 18446742974197924096,
},
Delete {
client_id: 11745387828182253567,
pos: 11719107999768421026,
len: 11719107999768421026,
},
NewOp {
client_id: 11719107999768421026,
pos: 11719107999768421026,
},
NewOp {
client_id: 11719107999768421026,
pos: 11719107999768421026,
},
NewOp {
client_id: 11719107999768421026,
pos: 11719107999768421026,
},
NewOp {
client_id: 11719107999768421026,
pos: 11719107999768421026,
},
NewOp {
client_id: 10850930719374615202,
pos: 18446628623220119190,
},
Delete {
client_id: 18446744073709551615,
pos: 18446743206884093439,
len: 15914838024376868095,
},
Delete {
client_id: 15863046628662107356,
pos: 98784247772,
len: 18446744069414584320,
},
Delete {
client_id: 18446744073709551615,
pos: 18446744073709551615,
len: 18446744073709551615,
},
Delete {
client_id: 16777471,
pos: 2954361355538333696,
len: 18446744073709551615,
},
Delete {
client_id: 11745387828182253567,
pos: 11719107999768421026,
len: 11719107999768421026,
},
NewOp {
client_id: 11719107999768421026,
pos: 11719107999768421026,
}, },
], ],
) )

View file

@ -35,11 +35,8 @@ impl<T: Sliceable> Slice<'_, T> {
} }
} }
#[allow(clippy::len_without_is_empty)]
pub trait HasLength { pub trait HasLength {
fn is_empty(&self) -> bool {
self.len() == 0
}
/// if the content is deleted, len should be zero /// if the content is deleted, len should be zero
fn len(&self) -> usize; fn len(&self) -> usize;

View file

@ -464,6 +464,17 @@ impl<'tree, T: Rle, A: RleTreeTrait<T>> SafeCursorMut<'tree, T, A> {
} }
} }
/// insert to the cursor start position with shift in offset. `shift` is based on the content_len.
///
/// self should be moved here, because after mutating self should be invalidate
pub fn insert_shift_notify<F>(self, value: T, shift: usize, notify: &mut F)
where
F: FnMut(&T, *mut LeafNode<'_, T, A>),
{
// SAFETY: we know the cursor is a valid pointer
unsafe { self.0.shift(shift).unwrap().insert_notify(value, notify) }
}
pub fn update_with_split<F, U>(self, update: U, notify: &mut F) pub fn update_with_split<F, U>(self, update: U, notify: &mut F)
where where
F: for<'a> FnMut(&T, *mut LeafNode<'a, T, A>), F: for<'a> FnMut(&T, *mut LeafNode<'a, T, A>),