From 5ce83d0188beeff1cf5a33654221f9153615b9ac Mon Sep 17 00:00:00 2001 From: Zixuan Chen Date: Mon, 31 Oct 2022 17:32:05 +0800 Subject: [PATCH] refactor: make client id type can be switching --- crates/loro-core/examples/mem.rs | 4 ++-- crates/loro-core/src/container/text/tracker.rs | 4 ++-- crates/loro-core/src/dag/test.rs | 2 +- crates/loro-core/src/fuzz.rs | 6 ++++-- crates/loro-core/src/id.rs | 6 +++--- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/crates/loro-core/examples/mem.rs b/crates/loro-core/examples/mem.rs index 5d7aea48..1c790ed1 100644 --- a/crates/loro-core/examples/mem.rs +++ b/crates/loro-core/examples/mem.rs @@ -26,7 +26,7 @@ pub fn main() { let start = Instant::now(); let mut loro = LoroCore::default(); let mut text = loro.get_or_create_root_text("text").unwrap(); - for i in 0..10 { + for i in 0..1 { for txn in txns.unwrap().as_array().unwrap() { let patches = txn .as_object() @@ -48,7 +48,7 @@ pub fn main() { drop(d); e.advance().unwrap(); let new_new_heap = alloc_stats.read().unwrap(); - println!("Apply Automerge Dataset 10X"); + println!("Apply Automerge Dataset 1X"); println!("Mem: {} MB", new_new_heap as f64 / 1024. / 1024.); println!("Used: {} ms", start.elapsed().as_millis()); } diff --git a/crates/loro-core/src/container/text/tracker.rs b/crates/loro-core/src/container/text/tracker.rs index a3776d58..11c58cfa 100644 --- a/crates/loro-core/src/container/text/tracker.rs +++ b/crates/loro-core/src/container/text/tracker.rs @@ -4,7 +4,7 @@ use smallvec::SmallVec; use crate::{ container::{list::list_op::ListOp, text::tracker::yata_impl::YataImpl}, debug_log, - id::{Counter, ID}, + id::{ClientID, Counter, ID}, op::OpContent, span::{HasIdSpan, IdSpan}, version::IdSpanVector, @@ -40,7 +40,7 @@ pub mod yata_impl; #[derive(Debug)] pub struct Tracker { #[cfg(feature = "fuzzing")] - client_id: u64, + client_id: ClientID, /// from start_vv to latest vv are applied start_vv: VersionVector, /// latest applied ops version vector diff --git a/crates/loro-core/src/dag/test.rs b/crates/loro-core/src/dag/test.rs index 5a362afe..ae2f1dd6 100644 --- a/crates/loro-core/src/dag/test.rs +++ b/crates/loro-core/src/dag/test.rs @@ -183,7 +183,7 @@ impl TestDag { fn _try_push_node( &mut self, node: &TestNode, - pending: &mut Vec<(u64, usize)>, + pending: &mut Vec<(ClientID, usize)>, i: usize, ) -> bool { let client_id = node.id.client_id; diff --git a/crates/loro-core/src/fuzz.rs b/crates/loro-core/src/fuzz.rs index f052d531..b98db3ac 100644 --- a/crates/loro-core/src/fuzz.rs +++ b/crates/loro-core/src/fuzz.rs @@ -4,7 +4,9 @@ use tabled::{TableIteratorExt, Tabled}; use crate::{ array_mut_ref, container::{text::text_container::TextContainer, Container}, - debug_log, LoroCore, + debug_log, + id::ClientID, + LoroCore, }; #[derive(arbitrary::Arbitrary, EnumAsInner, Clone, PartialEq, Eq, Debug)] @@ -289,7 +291,7 @@ pub fn test_single_client(mut actions: Vec) { pub fn test_multi_sites(site_num: u8, mut actions: Vec) { let mut sites = Vec::new(); for i in 0..site_num { - sites.push(LoroCore::new(Default::default(), Some(i as u64))); + sites.push(LoroCore::new(Default::default(), Some(i as ClientID))); } let mut applied = Vec::new(); diff --git a/crates/loro-core/src/id.rs b/crates/loro-core/src/id.rs index 0cebc0c7..c99eea8c 100644 --- a/crates/loro-core/src/id.rs +++ b/crates/loro-core/src/id.rs @@ -46,7 +46,7 @@ impl Ord for ID { } pub const ROOT_ID: ID = ID { - client_id: u64::MAX, + client_id: ClientID::MAX, counter: i32::MAX, }; @@ -61,7 +61,7 @@ impl From for ID { impl ID { #[inline] - pub fn new(client_id: u64, counter: Counter) -> Self { + pub fn new(client_id: ClientID, counter: Counter) -> Self { ID { client_id, counter } } @@ -72,7 +72,7 @@ impl ID { #[inline] pub fn is_null(&self) -> bool { - self.client_id == u64::MAX + self.client_id == ClientID::MAX } #[inline]