pub struct IntSpan { /* private fields */ }

Implementations

INTERFACE: Set creation and contents

INTERFACE: Set cardinality

INTERFACE: Member operations (mutate original set)

INTERFACE: Set binary operations (create new set)

INTERFACE: Set relations

INTERFACE: Indexing

Returns the index-th element of set, indices start from 1.

Negative indices count backwards from the end of the set.

Returns the index of an element in the set, indices start from 1

INTERFACE: Spans Ops

INTERFACE: Inter-set OPs

overlap

Returns the size of intersection of two sets.

set.overlap(&other) equivalent to set.intersect(&other).cardinality()

let set = IntSpan::from("1");
let other = IntSpan::from("1");
assert_eq!(set.overlap(&other), 1);
let other = IntSpan::from("2");
assert_eq!(set.overlap(&other), 0);
let set = IntSpan::from("1-5");
let other = IntSpan::from("1-10");
assert_eq!(set.overlap(&other), 5);
let set = IntSpan::from("1-5,6");
let other = IntSpan::from("6-10");
assert_eq!(set.overlap(&other), 1);

Returns the distance between sets, measured as follows.

  • If the sets overlap, then the distance is negative and given by - set.overlap(&other)

  • If the sets do not overlap, $d is positive and given by the distance on the integer line between the two closest islands of the sets.

let set = IntSpan::from("1");
let other = IntSpan::from("1");
assert_eq!(set.distance(&other), -1);
let other = IntSpan::from("");
assert_eq!(set.distance(&other), 0);
let other = IntSpan::from("2");
assert_eq!(set.distance(&other), 1);

let set = IntSpan::from("1-5");
let other = IntSpan::from("1-10");
assert_eq!(set.distance(&other), -5);
let other = IntSpan::from("10-15");
assert_eq!(set.distance(&other), 5);
let set = IntSpan::from("1-5,6");
let other = IntSpan::from("6-10");
assert_eq!(set.distance(&other), -1);

let set = IntSpan::from("1-5,10-15");
let other = IntSpan::from("5-9");
assert_eq!(set.distance(&other), -1);
let other = IntSpan::from("6");
assert_eq!(set.distance(&other), 1);
let other = IntSpan::from("7");
assert_eq!(set.distance(&other), 2);
let other = IntSpan::from("7-9");
assert_eq!(set.distance(&other), 1);
let other = IntSpan::from("16-20");
assert_eq!(set.distance(&other), 1);
let other = IntSpan::from("17-20");
assert_eq!(set.distance(&other), 2);

INTERFACE: Aliases

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.