diff --git a/Cargo.lock b/Cargo.lock index 180d97f1..61fdf3d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -161,9 +161,9 @@ dependencies = [ [[package]] name = "crdt-list" -version = "0.1.3" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15ab0245d29050a50d3431ad32d13bc59a187aa9c0e543b235ab8190f6b0d8af" +checksum = "44c6c20076c40cfc4fc484455bda1ba3cac6f9585b2e5a464b98fc4a2600f95b" dependencies = [ "arbitrary", "arref", diff --git a/crates/loro-core/Cargo.toml b/crates/loro-core/Cargo.toml index d7162495..454cc20f 100644 --- a/crates/loro-core/Cargo.toml +++ b/crates/loro-core/Cargo.toml @@ -19,7 +19,7 @@ thiserror = "1.0.31" im = "15.1.0" enum-as-inner = "0.5.1" num = "0.4.0" -crdt-list = "0.1.3" +crdt-list = "0.2.0" rand = { version = "0.8.5", optional = true } [dev-dependencies] diff --git a/crates/loro-core/fuzz/Cargo.lock b/crates/loro-core/fuzz/Cargo.lock index 70ac0e4a..34918b71 100644 --- a/crates/loro-core/fuzz/Cargo.lock +++ b/crates/loro-core/fuzz/Cargo.lock @@ -79,9 +79,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "crdt-list" -version = "0.1.3" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15ab0245d29050a50d3431ad32d13bc59a187aa9c0e543b235ab8190f6b0d8af" +checksum = "44c6c20076c40cfc4fc484455bda1ba3cac6f9585b2e5a464b98fc4a2600f95b" dependencies = [ "arbitrary", "arref", diff --git a/crates/loro-core/fuzz/Cargo.toml b/crates/loro-core/fuzz/Cargo.toml index 56ad18ab..04fe9816 100644 --- a/crates/loro-core/fuzz/Cargo.toml +++ b/crates/loro-core/fuzz/Cargo.toml @@ -9,7 +9,7 @@ edition = "2018" cargo-fuzz = true [dependencies] -crdt-list = "0.1.2" +crdt-list = "0.2.0" libfuzzer-sys = "0.4" [dependencies.loro-core] diff --git a/crates/loro-core/src/container/text/tracker/content_map.rs b/crates/loro-core/src/container/text/tracker/content_map.rs index 397eb355..083b6153 100644 --- a/crates/loro-core/src/container/text/tracker/content_map.rs +++ b/crates/loro-core/src/container/text/tracker/content_map.rs @@ -2,10 +2,13 @@ use std::ops::{Deref, DerefMut}; use rle::{ rle_tree::{Position, SafeCursor, SafeCursorMut, UnsafeCursor}, - HasLength, RleTree, + HasLength, RleTree, RleVec, }; -use crate::id::ID; +use crate::{ + id::{Counter, ID}, + span::IdSpan, +}; use super::y_span::{StatusChange, YSpan, YSpanTreeTrait}; @@ -137,6 +140,19 @@ impl ContentMap { (None, None) } } + + pub fn get_id_spans(&mut self, pos: usize, len: usize) -> RleVec { + let mut ans = RleVec::new(); + for cursor in self.iter_range(pos, Some(pos + len)) { + ans.push(IdSpan::new( + cursor.id.client_id, + cursor.id.counter, + cursor.id.counter + cursor.len as Counter, + )); + } + + ans + } } impl Deref for ContentMap { diff --git a/crates/loro-core/src/container/text/tracker/cursor_map.rs b/crates/loro-core/src/container/text/tracker/cursor_map.rs index 0b0d5908..efbfe2e1 100644 --- a/crates/loro-core/src/container/text/tracker/cursor_map.rs +++ b/crates/loro-core/src/container/text/tracker/cursor_map.rs @@ -5,7 +5,7 @@ use enum_as_inner::EnumAsInner; use rle::{ range_map::RangeMap, rle_tree::{node::LeafNode, Position, SafeCursor, SafeCursorMut}, - HasLength, Mergable, Sliceable, + HasLength, Mergable, RleVec, Sliceable, }; use crate::{id::ID, span::IdSpan}; @@ -20,7 +20,7 @@ pub(super) enum Marker { ptr: NonNull>, len: usize, }, - Delete(IdSpan), + Delete(RleVec), // TODO: REDO, UNDO } diff --git a/crates/loro-core/src/container/text/tracker/yata.rs b/crates/loro-core/src/container/text/tracker/yata.rs index b46fba64..e0455163 100644 --- a/crates/loro-core/src/container/text/tracker/yata.rs +++ b/crates/loro-core/src/container/text/tracker/yata.rs @@ -178,10 +178,12 @@ pub mod fuzz { test::{Action, TestFramework}, yata::Yata, }; + use rle::RleVec; use crate::{ container::text::tracker::Tracker, id::{ClientID, ID}, + span::IdSpan, }; use super::YataImpl; @@ -236,6 +238,20 @@ pub mod fuzz { pos % 10 + 1, ) } + + type DeleteOp = RleVec; + + fn new_del_op(container: &Self::Container, pos: usize, len: usize) -> Self::DeleteOp { + todo!() + } + + fn integrate_delete_op(container: &mut Self::Container, op: Self::DeleteOp) { + todo!() + } + + fn can_apply_del_op(container: &Self::Container, op: &Self::DeleteOp) -> bool { + todo!() + } } #[test] diff --git a/crates/rle/src/rle_tree/tree_trait.rs b/crates/rle/src/rle_tree/tree_trait.rs index 9ea733ec..ed49ef58 100644 --- a/crates/rle/src/rle_tree/tree_trait.rs +++ b/crates/rle/src/rle_tree/tree_trait.rs @@ -74,7 +74,7 @@ pub trait RleTreeTrait: Sized + Debug { fn update_cache_leaf(node: &mut LeafNode<'_, T, Self>); fn update_cache_internal(node: &mut InternalNode<'_, T, Self>); - /// - `child_index` can only equal to children.len() when it's zero + /// - `child_index` can only equal to children.len() when index out of range /// - We need the `offset` so we can perform `find_pos_internal(child, new_search_index)`. /// - We need the `pos` to determine whether the child is included or excluded /// - If not found, then `found` should be false and `child_index` should be the index of the insert position @@ -83,7 +83,7 @@ pub trait RleTreeTrait: Sized + Debug { index: Self::Int, ) -> FindPosResult; - /// - `child_index` can only equal to children.len() when it's zero + /// - `child_index` can only equal to children.len() when index out of range /// - if `pos == Middle`, we need to split the node /// - We need the third arg to determine whether the child is included or excluded /// - If not found, then `found` should be false and `child_index` should be the index of the insert position @@ -259,6 +259,7 @@ impl RleTreeTrait return; } + // TODO: Maybe panic if overlap? node.cache.end = node .children() .iter() diff --git a/supply-chain/audits.toml b/supply-chain/audits.toml index 2a7f0db7..7df62861 100644 --- a/supply-chain/audits.toml +++ b/supply-chain/audits.toml @@ -15,7 +15,7 @@ version = "0.5.1" [[audits.crdt-list]] who = "Zixuan Chen " criteria = "safe-to-deploy" -version = "0.1.3" +version = "0.2.0" notes = "I'm the author of this crate" [[audits.ctor]]