int_ranges

Crates.ioint_ranges
lib.rsint_ranges
version0.1.1
sourcesrc
created_at2022-05-12 06:45:58.541034
updated_at2022-05-12 08:32:36.821018
descriptionsimple ranges tools for integer
homepage
repositoryhttps://gitlab.com/hjiayz/int_ranges.git
max_upload_size
id585053
size9,810
ppc (hjiayz)

documentation

README

int_ranges

simple ranges tools for integer

    use int_ranges::{wrap,Ranges};
    let arr = vec![(1, 10), (30, 100), (11, 20)];
    let ranges: Vec<(i32, i32)> = Ranges::from(arr.clone()).into();

    assert_eq!(ranges, [(1, 20), (30, 100)]);

    let ranges: Vec<(i32, i32)> = Ranges::from(arr.clone()).invert().into();
    assert_eq!(ranges, [(i32::MIN, 0), (21, 29), (101, i32::MAX)]);

    assert_eq!(Ranges::<i32>::empty(), Ranges::<i32>::full().invert());
    assert_eq!(Ranges::<i32>::empty().invert(), Ranges::<i32>::full());
    assert_eq!(
        Ranges::from(vec![(1i32, 10)]).union(vec![(11i32, 20)]),
        Ranges::from(vec![wrap(1i32..=20)])
    );
    assert_eq!(
        Ranges::from(vec![(1i32, 10)]).intersect(vec![(11i32, 20)]),
        Ranges::empty()
    );

    assert_eq!(
        Ranges::from(vec![(1i32, 11)]).intersect(vec![(11i32, 20)]),
        Ranges::from(vec![(11i32,11)])
    );

    assert_eq!(
        Ranges::from(vec![(1i32, 15)]).intersect(vec![(11i32, 20)]),
        Ranges::from(vec![(11i32,15)])
    );

    assert_eq!(
        Ranges::from(vec![(1i32, 9)]).intersect(vec![(11i32, 20)]),
        Ranges::empty()
    );

    assert_eq!(
        Ranges::from(vec![(1i32, 10)]).contains(vec![(11i32, 20)]),
        false
    );

    assert_eq!(
        Ranges::from(vec![(1i32, 11)]).contains(vec![(11i32, 20)]),
        true
    );

Commit count: 3

cargo fmt