Skip to content

Commit

Permalink
Refactor rm unused code (#328)
Browse files Browse the repository at this point in the history
* chore: init

* fix: fuzz config

* refactor: rm unused code
  • Loading branch information
zxch3n authored Apr 22, 2024
1 parent 4700ead commit f99bfd8
Show file tree
Hide file tree
Showing 18 changed files with 136 additions and 853 deletions.
18 changes: 1 addition & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ members = [
"crates/rle",
"crates/loro-common",
"crates/loro-internal",
"crates/loro-preload",
"crates/loro-wasm",
"crates/fuzz",
]
Expand Down
3 changes: 2 additions & 1 deletion crates/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
loro = { path = "../loro", features = ["test_utils"] }
loro = { path = "../loro" }
loro-internal = { path = "../loro-internal", features = ["test_utils"] }
arbitrary = "1"
tabled = "0.10"
debug-log = { workspace = true }
Expand Down
34 changes: 9 additions & 25 deletions crates/fuzz/fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/fuzz/src/container/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl Actionable for TreeAction {

match action {
TreeActionInner::Create => {
let id = tree.next_tree_id();
let id = tree.__internal__next_tree_id();
*target = (id.peer, id.counter);
}
TreeActionInner::Delete => {
Expand Down
41 changes: 41 additions & 0 deletions crates/fuzz/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,44 @@ fn random_fuzz_1s_5sites_1() {
fn random_fuzz_1s_5sites_2() {
arbtest::builder().budget_ms(1000).run(|u| prop(u, 5));
}

#[test]
fn test_unknown() {
test_multi_sites(
5,
vec![
FuzzTarget::Map,
FuzzTarget::List,
FuzzTarget::Tree,
FuzzTarget::Text,
],
&mut [
Handle {
site: 34,
target: 115,
container: 4,
action: Generic(GenericAction {
value: I32(62063364),
bool: false,
key: 771987715,
pos: 217020518514230019,
length: 217234923281646339,
prop: 6234107865851074949,
}),
},
Handle {
site: 3,
target: 3,
container: 0,
action: Generic(GenericAction {
value: I32(0),
bool: false,
key: 0,
pos: 0,
length: 0,
prop: 0,
}),
},
],
)
}
54 changes: 0 additions & 54 deletions crates/loro-common/src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,62 +491,8 @@ impl From<ID> for IdSpan {

#[cfg(test)]
mod test_id_span {
use rle::RleVecWithIndex;

use super::*;

macro_rules! id_spans {
($([$peer:expr, $from:expr, $to:expr]),*) => {
{
let mut id_spans = RleVecWithIndex::new();
$(
id_spans.push(IdSpan {
peer: $peer,
counter: CounterSpan::new($from, $to),
});
)*
id_spans
}
};
}

#[test]
fn test_id_span_rle_vec() {
let mut id_span_vec = RleVecWithIndex::new();
id_span_vec.push(IdSpan {
peer: 0,
counter: CounterSpan::new(0, 2),
});
assert_eq!(id_span_vec.merged_len(), 1);
assert_eq!(id_span_vec.atom_len(), 2);
id_span_vec.push(IdSpan {
peer: 0,
counter: CounterSpan::new(2, 4),
});
assert_eq!(id_span_vec.merged_len(), 1);
assert_eq!(id_span_vec.atom_len(), 4);
id_span_vec.push(IdSpan {
peer: 2,
counter: CounterSpan::new(2, 4),
});
assert_eq!(id_span_vec.merged_len(), 2);
assert_eq!(id_span_vec.atom_len(), 6);
}

#[test]
fn slice() {
let id_span_vec = id_spans!([0, 0, 2], [0, 2, 4], [2, 2, 4]);
let slice: Vec<IdSpan> = id_span_vec.slice_iter(2, 5).map(|x| x.into()).collect();
assert_eq!(slice, id_spans!([0, 2, 4], [2, 2, 3]).to_vec());
}

#[test]
fn backward() {
let id_span_vec = id_spans!([0, 100, 98], [0, 98, 90], [2, 2, 4], [2, 8, 4]);
let slice: Vec<IdSpan> = id_span_vec.slice_iter(5, 14).map(|x| x.into()).collect();
assert_eq!(slice, id_spans!([0, 95, 90], [2, 2, 4], [2, 8, 6]).to_vec());
}

#[test]
fn merge() {
let mut a = CounterSpan::new(0, 2);
Expand Down
1 change: 0 additions & 1 deletion crates/loro-internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ keywords = ["crdt", "local-first"]

[dependencies]
rle = { path = "../rle", version = "0.4.0", package = "loro-rle" }
loro-preload = { path = "../loro-preload", version = "0.4.0" }
loro-common = { path = "../loro-common", version = "0.4.0" }
smallvec = { version = "1.8.0", features = ["serde"] }
postcard = "1"
Expand Down
9 changes: 9 additions & 0 deletions crates/loro-internal/examples/encoding.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::time::Instant;

use bench_utils::TextAction;
use loro_internal::LoroDoc;

Expand Down Expand Up @@ -37,8 +39,15 @@ fn main() {
txn.commit().unwrap();
}

let start = Instant::now();
let snapshot = loro.export_snapshot();
println!("Snapshot time {}ms", start.elapsed().as_millis());
let output = miniz_oxide::deflate::compress_to_vec(&snapshot, 6);
println!(
"Snapshot+compression time {}ms",
start.elapsed().as_millis()
);

println!(
"snapshot size {} after compression {}",
snapshot.len(),
Expand Down
4 changes: 2 additions & 2 deletions crates/loro-internal/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2335,8 +2335,8 @@ impl TreeHandler {
}
}

#[cfg(feature = "test_utils")]
pub fn next_tree_id(&self) -> TreeID {
#[allow(non_snake_case)]
pub fn __internal__next_tree_id(&self) -> TreeID {
match &self.inner {
MaybeDetached::Detached(d) => {
let d = d.try_lock().unwrap();
Expand Down
19 changes: 0 additions & 19 deletions crates/loro-preload/Cargo.toml

This file was deleted.

5 changes: 0 additions & 5 deletions crates/loro-preload/README.md

This file was deleted.

Loading

0 comments on commit f99bfd8

Please sign in to comment.