Crates.io | vec_clock |
lib.rs | vec_clock |
version | 0.2.0 |
source | src |
created_at | 2024-12-05 13:24:09.507095 |
updated_at | 2024-12-08 05:24:05.379389 |
description | Vector clock implimentation. |
homepage | |
repository | https://github.com/seto1221/vec_clock |
max_upload_size | |
id | 1473190 |
size | 101,432 |
A library for vector clock.
use vec_clock as vc;
let mut clock = vc::new(vec![0u64; 3], 0).unwrap();
assert_eq!(clock.len(), 3);
assert_eq!(clock.self_index(), 0);
assert_eq!(clock.compare(&[0, 0, 0]).unwrap(), vc::CompareState::Same);
assert_eq!(format!("{:?}", clock), "VecClock { time: [0, 0, 0], self_index: 0 }");
assert_eq!(format!("{:?}", clock.as_slice()), "[0, 0, 0]");
let mut time = clock.time();
assert_eq!(time.len(), 3);
assert_eq!(time.compare(&[1, 0, 0]).unwrap(), vc::CompareState::Same);
assert_eq!(time.compare(&[1, 1, 0]).unwrap(), vc::CompareState::Before);
assert_eq!(time.compare(vc::convert(&[0u32, 1, 0])).unwrap(), vc::CompareState::Concurrent);
assert_eq!(time.compare(vc::try_convert(&[0i32, 0, 0]).unwrap()).unwrap(), vc::CompareState::After);
assert_eq!(format!("{:?}", time), "VecTime([1, 0, 0])");
assert_eq!(format!("{:?}", time.as_slice()), "[1, 0, 0]");
time = clock.time();
assert_eq!(time.compare(&[2, 0, 0]).unwrap(), vc::CompareState::Same);
time = clock.time();
assert_eq!(time.compare(&[3, 0, 0]).unwrap(), vc::CompareState::Same);
time = clock.time_by(&[0, 1, 2]).unwrap();
assert_eq!(time.compare(&[4, 1, 2]).unwrap(), vc::CompareState::Same);
time = clock.time_by(vc::try_convert(&[0i32, 1, 2]).unwrap()).unwrap();
assert_eq!(time.compare(&[5, 1, 2]).unwrap(), vc::CompareState::Same);
assert_eq!(clock.compare(&[5, 1, 2]).unwrap(), vc::CompareState::Same);