vec_clock

Crates.iovec_clock
lib.rsvec_clock
version0.2.0
sourcesrc
created_at2024-12-05 13:24:09.507095
updated_at2024-12-08 05:24:05.379389
descriptionVector clock implimentation.
homepage
repositoryhttps://github.com/seto1221/vec_clock
max_upload_size
id1473190
size101,432
seto (seto1221)

documentation

README

Vector Clock implementation for Rust

A library for vector clock.

Examples

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);
Commit count: 19

cargo fmt