Crates.io | iter-set-ops |
lib.rs | iter-set-ops |
version | 0.2.3 |
source | src |
created_at | 2024-05-06 22:39:39.250977 |
updated_at | 2024-05-14 07:15:58.420222 |
description | Fast set operations on an arbitrary number of sorted deduplicated iterators |
homepage | https://crates.io/crates/iter-set-ops |
repository | https://github.com/imartayan/iter-set-ops |
max_upload_size | |
id | 1231575 |
size | 29,438 |
Fast set operations on an arbitrary number of sorted deduplicated iterators.
merge_iters_by
/ intersect_iters_by
use iter_set_ops::intersect_iters;
let it1 = 1u8..=5;
let it2 = 3u8..=7;
let it3 = 2u8..=4;
let mut iters = [it1, it2, it3];
// intersect it1, it2 and it3
let res: Vec<_> = intersect_iters(&mut iters).collect();
assert_eq!(res, vec![3, 4]);
// the computation stops before exhausting all the iterators
assert!(iters[1].next().is_some());
use iter_set_ops::merge_iters_by;
let it1 = (1u8..=5).rev();
let it2 = (3u8..=7).rev();
let it3 = (2u8..=4).rev();
let mut iters = [it1, it2, it3];
// merge it1, it2 and it3 using a reverse comparison operator
let res: Vec<_> = merge_iters_by(&mut iters, |x, y| y.cmp(x)).collect();
assert_eq!(res, vec![7, 6, 5, 4, 3, 2, 1]);
use iter_set_ops::merge_iters_detailed;
let it1 = 1u8..=2;
let it2 = 2u8..=3;
let mut iters = [it1, it2];
// merge it1 and it2 while keeping the details of each item
let res: Vec<_> = merge_iters_detailed(&mut iters).collect();
assert_eq!(
res,
vec![
vec![(0, 1)], // `1` comes from the first iterator
vec![(1, 2), (0, 2)], // `2` comes from both iterators
vec![(1, 3)] // `3` comes from the second iterator
]
);