refactor: make client id type can be switching

This commit is contained in:
Zixuan Chen 2022-10-31 17:32:05 +08:00
parent 261fb329ee
commit 5ce83d0188
5 changed files with 12 additions and 10 deletions

View file

@ -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());
}

View file

@ -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

View file

@ -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;

View file

@ -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<Action>) {
pub fn test_multi_sites(site_num: u8, mut actions: Vec<Action>) {
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();

View file

@ -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<u128> 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]