threshold-rs
: threshold data structures in Rust!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
```rust use threshold::{clock, *};
let vclock0 = clock::vclockfromseqs(vec![10, 5, 5]); let vclock1 = clock::vclockfromseqs(vec![8, 10, 6]); let vclock2 = clock::vclockfrom_seqs(vec![9, 8, 7]);
let mut tclock = TClock::new(); tclock.add(vclock0); tclock.add(vclock1); tclock.add(vclock_2);
let vclockt1 = clock::vclockfromseqs(vec![10, 10, 7]); let vclockt2 = clock::vclockfromseqs(vec![9, 8, 6]); let vclockt3 = clock::vclockfrom_seqs(vec![8, 5, 5]);
asserteq!(tclock.thresholdunion(1), vclockt1); asserteq!(tclock.thresholdunion(2), vclockt2); asserteq!(tclock.thresholdunion(3), vclock_t3); ```
Licensed under either of
at your option.
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.