Skip to content

Commit

Permalink
fix: tree transform when a and b is equal (#371)
Browse files Browse the repository at this point in the history
* test: add test
  • Loading branch information
Leeeon233 authored May 25, 2024
1 parent 7fc85b1 commit 4a0c8b6
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 11 deletions.
52 changes: 48 additions & 4 deletions crates/fuzz/tests/undo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use fuzz::{
};
use loro_common::ContainerType::*;

// #[ctor::ctor]
// fn init() {
// dev_utils::setup_test_log();
// }
#[ctor::ctor]
fn init() {
dev_utils::setup_test_log();
}

#[test]
fn undo_tree_with_map() {
Expand Down Expand Up @@ -120,3 +120,47 @@ fn redo_tree_id_diff() {
],
);
}

#[test]
fn tree_delete() {
test_multi_sites(
5,
vec![FuzzTarget::All],
&mut [
Handle {
site: 33,
target: 147,
container: 2,
action: Generic(GenericAction {
value: I32(2071690107),
bool: true,
key: 2223278715,
pos: 11357407135578037636,
length: 11357407135578037661,
prop: 11357407135578037661,
}),
},
SyncAllUndo {
site: 223,
op_len: 33721747,
},
Handle {
site: 2,
target: 2,
container: 255,
action: Generic(GenericAction {
value: I32(-1971618949),
bool: false,
key: 2644345988,
pos: 11357407135578037661,
length: 11357407135578037661,
prop: 11357407135578037661,
}),
},
SyncAllUndo {
site: 157,
op_len: 2644352413,
},
],
)
}
20 changes: 13 additions & 7 deletions crates/loro-internal/src/delta/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct TreeDiffItem {
pub action: TreeExternalDiff,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub enum TreeExternalDiff {
Create {
parent: Option<TreeID>,
Expand Down Expand Up @@ -62,16 +62,22 @@ impl TreeDiff {
.enumerate()
.map(|(i, d)| (d.target, (&d.action, i)))
.collect();
if !left_prior {
let mut removes = Vec::new();
for (target, _) in b_update {

let mut removes = Vec::new();
for (target, diff) in b_update {
if self_update.contains_key(&target) && diff == self_update.get(&target).unwrap().0 {
let (_, i) = self_update.remove(&target).unwrap();
removes.push(i);
continue;
}
if !left_prior {
if let Some((_, i)) = self_update.remove(&target) {
removes.push(i);
}
}
for i in removes.into_iter().sorted().rev() {
self.diff.remove(i);
}
}
for i in removes.into_iter().sorted().rev() {
self.diff.remove(i);
}
let mut b_parent = FxHashMap::default();

Expand Down

0 comments on commit 4a0c8b6

Please sign in to comment.