diff --git a/Cargo.lock b/Cargo.lock index 75459f1a..4fa22134 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -665,6 +665,7 @@ dependencies = [ "enum-as-inner 0.5.1", "enum_dispatch", "fxhash", + "itertools 0.12.1", "loro", "loro-internal", "rand", @@ -913,6 +914,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.5" @@ -1044,7 +1054,7 @@ dependencies = [ "generic-btree", "getrandom", "im", - "itertools 0.11.0", + "itertools 0.12.1", "js-sys", "leb128", "loro-common", diff --git a/Cargo.toml b/Cargo.toml index f164991f..6c76cc0a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,3 +24,4 @@ tracing = { version = "0.1", features = [ "release_max_level_warn", ] } serde_columnar = { version = "0.3.4" } +itertools = "0.12.1" diff --git a/crates/fuzz/Cargo.toml b/crates/fuzz/Cargo.toml index 30a5768d..eb6e4f1f 100644 --- a/crates/fuzz/Cargo.toml +++ b/crates/fuzz/Cargo.toml @@ -9,13 +9,14 @@ publish = false [dependencies] loro = { path = "../loro" } loro-internal = { path = "../loro-internal", features = ["test_utils"] } -arbitrary = "1" -tabled = "0.10" fxhash = { workspace = true } enum_dispatch = { workspace = true } enum-as-inner = { workspace = true } -rand = "0.8.5" tracing = { workspace = true } +itertools = { workspace = true } +arbitrary = "1" +tabled = "0.10" +rand = "0.8.5" [dev-dependencies] ctor = "0.2" diff --git a/crates/fuzz/fuzz/Cargo.lock b/crates/fuzz/fuzz/Cargo.lock index c172a614..bb822843 100644 --- a/crates/fuzz/fuzz/Cargo.lock +++ b/crates/fuzz/fuzz/Cargo.lock @@ -224,6 +224,7 @@ dependencies = [ "enum-as-inner 0.5.1", "enum_dispatch", "fxhash", + "itertools 0.12.1", "loro", "loro-internal", "rand", @@ -257,7 +258,7 @@ dependencies = [ "arref", "fxhash", "heapless 0.7.17", - "itertools", + "itertools 0.11.0", "loro-thunderdome", "proc-macro2", ] @@ -372,6 +373,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.10" @@ -422,7 +432,7 @@ dependencies = [ [[package]] name = "loro" -version = "0.5.0" +version = "0.5.1" dependencies = [ "either", "enum-as-inner 0.6.0", @@ -434,7 +444,7 @@ dependencies = [ [[package]] name = "loro-common" -version = "0.5.0" +version = "0.5.1" dependencies = [ "arbitrary", "enum-as-inner 0.6.0", @@ -449,7 +459,7 @@ dependencies = [ [[package]] name = "loro-delta" -version = "0.5.0" +version = "0.5.1" dependencies = [ "arrayvec", "enum-as-inner 0.5.1", @@ -460,7 +470,7 @@ dependencies = [ [[package]] name = "loro-internal" -version = "0.5.0" +version = "0.5.1" dependencies = [ "append-only-bytes", "arbitrary", @@ -473,7 +483,7 @@ dependencies = [ "generic-btree", "getrandom", "im", - "itertools", + "itertools 0.12.1", "leb128", "loro-common", "loro-delta", @@ -496,7 +506,7 @@ dependencies = [ [[package]] name = "loro-rle" -version = "0.5.0" +version = "0.5.1" dependencies = [ "append-only-bytes", "arref", @@ -827,7 +837,7 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a5d54dd7e7a1ec134c842f8a3bdb5a1fc662d002682e0457f976f3046cf9ccf8" dependencies = [ - "itertools", + "itertools 0.11.0", "postcard", "serde", "serde_columnar_derive", diff --git a/crates/fuzz/src/container/tree.rs b/crates/fuzz/src/container/tree.rs index c5ccfe44..98d57428 100644 --- a/crates/fuzz/src/container/tree.rs +++ b/crates/fuzz/src/container/tree.rs @@ -6,6 +6,7 @@ use std::{ }; use fxhash::FxHashMap; +use itertools::Itertools; use loro::{ event::Diff, Container, ContainerID, ContainerType, LoroDoc, LoroError, LoroTree, LoroValue, TreeExternalDiff, TreeID, @@ -447,23 +448,17 @@ impl ApplyDiff for TreeTracker { fn to_value(&self) -> LoroValue { let mut list: Vec> = Vec::new(); - for (i, node) in self.iter().enumerate() { - node.to_value(i, &mut list); + let mut q = VecDeque::from_iter( + self.iter() + .sorted_unstable_by_key(|x| &x.position) + .enumerate(), + ); + + while let Some((i, node)) = q.pop_front() { + list.push(node.to_value(i)); + q.extend(node.children.iter().enumerate()); } - list.sort_by_key(|x| { - let parent = if let LoroValue::String(p) = x.get("parent").unwrap() { - Some(p.clone()) - } else { - None - }; - - ( - parent, - *x.get("index").unwrap().as_i64().unwrap(), - x.get("id").unwrap().as_string().unwrap().clone(), - ) - }); list.into() } } @@ -500,10 +495,7 @@ impl TreeNode { } } - fn to_value(&self, index: usize, list: &mut Vec>) { - for (i, child) in self.children.iter().enumerate() { - child.to_value(i, list); - } + fn to_value(&self, index: usize) -> FxHashMap { let mut map = FxHashMap::default(); map.insert("id".to_string(), self.id.to_string().into()); map.insert("meta".to_string(), self.meta.to_value()); @@ -516,6 +508,6 @@ impl TreeNode { ); map.insert("position".to_string(), self.position.clone().into()); map.insert("index".to_string(), (index as i64).into()); - list.push(map); + map } } diff --git a/crates/loro-internal/Cargo.toml b/crates/loro-internal/Cargo.toml index a08deda1..7eb106b9 100644 --- a/crates/loro-internal/Cargo.toml +++ b/crates/loro-internal/Cargo.toml @@ -35,7 +35,7 @@ serde_json = { version = "1" } arref = "0.1.0" serde_columnar = { workspace = true } append-only-bytes = { version = "0.1.12", features = ["u32_range"] } -itertools = "0.11.0" +itertools = { workspace = true } enum_dispatch = { workspace = true } im = "15.1.0" generic-btree = { version = "^0.10.5" }