32 releases (7 breaking)

✓ Uses Rust 2018 edition

new 0.8.2 May 12, 2020
0.7.1 May 8, 2020
0.6.8 Feb 3, 2020
0.6.1 Dec 26, 2019
0.2.6 Aug 14, 2019

#129 in Data structures

Download history 57/week @ 2020-01-24 76/week @ 2020-01-31 9/week @ 2020-02-07 185/week @ 2020-02-14 81/week @ 2020-02-21 46/week @ 2020-02-28 54/week @ 2020-03-06 30/week @ 2020-03-13 81/week @ 2020-03-20 30/week @ 2020-03-27 28/week @ 2020-04-03 199/week @ 2020-04-10 30/week @ 2020-04-17 22/week @ 2020-04-24 33/week @ 2020-05-01 95/week @ 2020-05-08

288 downloads per month

MIT/Apache

115KB
1.5K SLoC

crates.io docs.rs Build Status Coverage Status

threshold-rs: threshold data structures in Rust!

Example

Assume multiset X is {10: 1, 8: 2, 6: 3, 5: 1}. This means that event 10 was seen once, event 8 twice, and so on.

Assume that these events come from vector clocks, and thus seeing event 10 means seeing all events from 1 to 10.

If, for example, we want the event that was seen at least 4 times (i.e. our threshold is 4), we should get event 6.

Assume threshold(u64, X) -> Option<u64> where the first argument is the threshold desired and the output the event that passes the threshold (in case there's one). Then:

  • threshold(1, X) = Some(10)
  • threshold(2, X) = Some(8)
  • threshold(3, X) = Some(8)
  • threshold(4, X) = Some(6)
  • threshold(7, X) = Some(5)
  • threshold(8, X) = None

Code Example

use threshold::{clock, *};

let vclock_0 = clock::vclock_from_seqs(vec![10, 5, 5]);
let vclock_1 = clock::vclock_from_seqs(vec![8, 10, 6]);
let vclock_2 = clock::vclock_from_seqs(vec![9, 8, 7]);

let mut tclock = TClock::new();
tclock.add(vclock_0);
tclock.add(vclock_1);
tclock.add(vclock_2);

let vclock_t1 = clock::vclock_from_seqs(vec![10, 10, 7]);
let vclock_t2 = clock::vclock_from_seqs(vec![9, 8, 6]);
let vclock_t3 = clock::vclock_from_seqs(vec![8, 5, 5]);

assert_eq!(tclock.threshold_union(1), vclock_t1);
assert_eq!(tclock.threshold_union(2), vclock_t2);
assert_eq!(tclock.threshold_union(3), vclock_t3);

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~0.6–1MB
~24K SLoC