[][src]Struct ranges::Ranges

pub struct Ranges<T: Domain> { /* fields omitted */ }

A range set storing GenericRanges in the most memory-optimal fashion possible.

The two guarantees of storing ranges disjoint and sorted allows for the following optimizations:

  • keeping them ordered, upper and lower bounds for searches can be used to keep the search space as small as possible
  • storing them disjoint is a by-product of automatically merging newly inserted ranges, which additionally helps to reduce reindexing of the internal vector

Implementations

impl<T: Domain> Ranges<T>[src]

#[must_use]pub fn contains(&self, item: &T) -> bool[src]

Returns true if the given item is contained in any of the internal disjoint ranges.

Note

In contrast to the GenericRange constructor, item values will not be clamped to the domain and immediately return false if outside of it.

Example

use ranges::Ranges;

let ranges = Ranges::from(vec![0..3, 5..10]);
assert!(ranges.contains(&2));
assert!(ranges.contains(&7));
assert!(!ranges.contains(&4));

impl<T: Domain> Ranges<T>[src]

#[must_use]pub fn difference<R>(self, other: R) -> Self where
    R: Into<Self>, 
[src]

Calculates the relative complement (difference) of two ranges.

Examples

Overlapping ranges:

use ranges::Ranges;

let ranges1 = Ranges::from(0..5);
let ranges2 = 3..8;

 assert_eq!(ranges1 - ranges2, (0..3).into());

Equal ranges:

use ranges::Ranges;

let ranges1 = Ranges::from(0..10);
let ranges2 = 0..10;

assert!((ranges1 - ranges2).is_empty());

impl<T: Domain> Ranges<T>[src]

pub fn insert<R>(&mut self, range: R) -> bool where
    R: Into<GenericRange<T>>, 
[src]

Returns true if any element or the internal vector was modified to accommodate range. This means false is returned if and only if nothing has changed.

Examples

Empty:

use ranges::Ranges;

let mut ranges = Ranges::new();
assert!(ranges.insert(0..3));
assert_eq!(ranges, (0..3).into())

Collision with internal expansion of existing entry:

use ranges::Ranges;

let mut ranges = Ranges::from(0..3);
assert!(ranges.insert(2..5));
assert_eq!(ranges, (0..5).into())

No change in internal vector:

use ranges::Ranges;

let mut ranges = Ranges::from(0..10);
assert!(!ranges.insert(3..7));
assert_eq!(ranges, (0..10).into())

impl<T: Domain> Ranges<T>[src]

#[must_use]pub fn intersect<R>(self, other: R) -> Self where
    R: Into<Self>, 
[src]

Calculates the intersection of two ranges.

Examples

Single overlapping ranges:

use ranges::Ranges;

let ranges1 = Ranges::from(0..5);
let ranges2 = 3..8;

assert_eq!(ranges1 & ranges2, (3..5).into());

Multiple overlapping ranges:

use ranges::{GenericRange, Ranges};

let ranges1 = Ranges::from(0..9);
let ranges2 = Ranges::from(vec![-1..3, 6..11]);

assert_eq!(ranges1 & ranges2, vec![0..3, 6..9].into())

impl<T: Domain> Ranges<T>[src]

#[must_use]pub fn invert(self) -> Self[src]

Inverts the range set.

Examples

Empty set:

use ranges::Ranges;

assert_eq!(!Ranges::<usize>::new(), Ranges::full());

Single entry:

use ranges::{GenericRange, Ranges};

let ranges = Ranges::from(0..10);
assert_eq!(
    !ranges,
    vec![GenericRange::new_less_than(0), GenericRange::new_at_least(10)].into()
);

Multiple entries:

use ranges::{GenericRange, Ranges};

let ranges = Ranges::from(vec![GenericRange::from(0..10), (15..=20).into()]);
assert_eq!(
    !ranges,
    vec![
        GenericRange::new_less_than(0),
        (10..15).into(),
        GenericRange::new_greater_than(20)
    ].into()
);

impl<T: Domain> Ranges<T>[src]

pub fn remove<R>(&mut self, range: R) -> bool where
    R: Into<GenericRange<T>>, 
[src]

Returns true if any element or the internal vector was modified to remove range. This means false is returned if and only if nothing has changed.

Examples

Empty set.

use ranges::Ranges;

let mut ranges = Ranges::new();
assert!(!ranges.remove(0..3));

Single entry but no collision.

use ranges::Ranges;

let mut ranges = Ranges::from(0..3);
assert!(!ranges.remove(5..10));
assert_eq!(ranges, (0..3).into())

Single entry with collision in the middle.

use ranges::{GenericRange, Ranges};

let mut ranges = Ranges::from(0..10);
assert!(ranges.remove(2..5));
assert_eq!(ranges, vec![0..2, 5..10].into())

impl<T: Domain> Ranges<T>[src]

#[must_use]pub fn symmetric_difference<R>(self, other: R) -> Self where
    R: Into<Self>, 
[src]

Calculates the relative complement (difference) of two ranges.

Examples

Empty range.

use ranges::Ranges;

let ranges1 = Ranges::new();
let ranges2 = 0..10;

assert_eq!(ranges1 ^ ranges2, (0..10).into());

Touching ranges.

use ranges::Ranges;

let ranges1 = Ranges::from(0..3);
let ranges2 = 3..8;

assert_eq!(ranges1 ^ ranges2, (0..8).into());

Overlapping multiple ranges.

use ranges::{GenericRange, Ranges};

let ranges1 = Ranges::from(vec![0..5, 6..9]);
let ranges2 = 3..8;

assert_eq!(
    ranges1 ^ ranges2,
    vec![0..3, 5..6, 8..9].into()
);

impl<T: Domain> Ranges<T>[src]

#[must_use]pub fn union<R>(self, other: R) -> Self where
    R: Into<Self>, 
[src]

Calculates the union of two ranges.

Examples

Empty and single-entry ranges.

use ranges::Ranges;

let ranges1 = Ranges::new();
let ranges2 = 0..10;

assert_eq!(ranges1 | ranges2, (0..10).into());

Disjoint ranges.

use ranges::Ranges;

let ranges1 = Ranges::from(0..3);
let ranges2 = 5..8;

assert_eq!(ranges1 | ranges2, vec![0..3, 5..8].into());

Overlapping ranges.

use ranges::Ranges;

let ranges1 = Ranges::from(vec![0..5, 6..9]);
let ranges2 = 3..8;

assert_eq!(ranges1 | ranges2, (0..9).into());

impl<T: Domain> Ranges<T>[src]

#[must_use]pub fn new() -> Self[src]

Creates a new empty Ranges with an initial capacity of 0.

#[must_use]pub fn with_capacity(capacity: usize) -> Self[src]

Initializes the underlying vector with a given capacity.

#[must_use]pub fn full() -> Self[src]

Initializes the underlying vector with a single full range.

#[must_use]pub fn is_full(&self) -> bool where
    T: PartialEq
[src]

Returns true if the whole domain is in this range.

#[must_use]pub fn len(&self) -> usize[src]

Returns the amount of saved disjoint ranges.

#[must_use]pub fn is_empty(&self) -> bool[src]

Returns true if there are no ranges and we have an empty set.

#[must_use]pub fn find_intersecting_ranges(
    &self,
    other: &GenericRange<T>
) -> Option<(usize, usize)>
[src]

Find the GenericRanges in self which at least touch other.

Since other is a GenericRange (i.e. contiguous), the overlapping ranges must all be consecutive. Therefore, this only returns the indices of the first and last ranges which overlap.

This returns a (start, end) pair of indices into self.ranges.

Example

use ranges::Ranges;

let ranges = Ranges::from(vec![0..5, 10..20, 25..30, 45..50]);
assert_eq!(ranges.find_intersecting_ranges(&(7..47).into()), Some((1, 3)))

#[must_use]pub fn as_slice(&self) -> &[GenericRange<T>][src]

Returns the internal vector of GenericRanges as a slice.

Trait Implementations

impl<T, I> Add<I> for Ranges<T> where
    I: Into<GenericRange<T>>,
    T: Domain
[src]

This calls self.insert(other).

type Output = Self

The resulting type after applying the + operator.

impl<T, I> AddAssign<I> for Ranges<T> where
    I: Into<GenericRange<T>>,
    T: Domain
[src]

This calls self.insert(other).

impl<T: Domain> AsRef<Vec<GenericRange<T>>> for Ranges<T>[src]

impl<T: Binary + Domain> Binary for Ranges<T>[src]

Non-Debug formatting uses interval notation and formats the bound values according to the given formatting arguments.

Note

Unless disabled by using the - formatting argument, a whitespace will be printed after the bound separator. Because there is currently no use for -, it will have no effect on the underlying bound values. This might change if requested or core/std makes use of it.

Examples

Single entries. These are formatted like a single GenericRange.

use ranges::Ranges;

assert_eq!(format!("{}", Ranges::from(1..2)), "{1}");
assert_eq!(format!("{}", Ranges::from(1..=2)), "[1, 2]");
assert_eq!(format!("{}", Ranges::from(42..)), "[42, 2147483647]");
assert_eq!(format!("{:03}", Ranges::from(1..2)), "{001}");
assert_eq!(format!("{:02X}", Ranges::from(1..=10)), "[01, 0A]");
assert_eq!(format!("{:-#}", Ranges::from(42..=100)), "[42,100]");

Multiple entries. is used for an empty set and is used to concatenate disjoint entries.

use ranges::Ranges;

let mut ranges = Ranges::from(..6);
ranges.insert(7..=7);
ranges.insert(9..=9);
ranges.insert(15..);
assert_eq!(
    format!("{}", ranges),
    "[-2147483648, 6) \u{222a} {7, 9} \u{222a} [15, 2147483647]"
);

impl<T, I> BitAnd<I> for Ranges<T> where
    I: Into<Ranges<T>>,
    T: Domain
[src]

type Output = Self

The resulting type after applying the & operator.

impl<T: Domain> BitAndAssign<Ranges<T>> for Ranges<T>[src]

This calls self.intersect(other) and replaces self with the result.

impl<T, I> BitOr<I> for Ranges<T> where
    I: Into<Ranges<T>>,
    T: Domain
[src]

This calls self.union(other).

type Output = Self

The resulting type after applying the | operator.

impl<T, I> BitOrAssign<I> for Ranges<T> where
    I: Into<Ranges<T>>,
    T: Domain
[src]

This calls self.union(other) and replaces self with the result.

impl<T, I> BitXor<I> for Ranges<T> where
    I: Into<Ranges<T>>,
    T: Domain
[src]

type Output = Self

The resulting type after applying the ^ operator.

impl<T, I> BitXorAssign<I> for Ranges<T> where
    I: Into<Ranges<T>>,
    T: Domain
[src]

This calls self.symmetric_difference(other) and replaces self with the result.

impl<T: Clone + Domain> Clone for Ranges<T>[src]

impl<T: Debug + Domain> Debug for Ranges<T>[src]

impl<T: Default + Domain> Default for Ranges<T>[src]

impl<T: Display + Domain> Display for Ranges<T>[src]

Non-Debug formatting uses interval notation and formats the bound values according to the given formatting arguments.

Note

Unless disabled by using the - formatting argument, a whitespace will be printed after the bound separator. Because there is currently no use for -, it will have no effect on the underlying bound values. This might change if requested or core/std makes use of it.

Examples

Single entries. These are formatted like a single GenericRange.

use ranges::Ranges;

assert_eq!(format!("{}", Ranges::from(1..2)), "{1}");
assert_eq!(format!("{}", Ranges::from(1..=2)), "[1, 2]");
assert_eq!(format!("{}", Ranges::from(42..)), "[42, 2147483647]");
assert_eq!(format!("{:03}", Ranges::from(1..2)), "{001}");
assert_eq!(format!("{:02X}", Ranges::from(1..=10)), "[01, 0A]");
assert_eq!(format!("{:-#}", Ranges::from(42..=100)), "[42,100]");

Multiple entries. is used for an empty set and is used to concatenate disjoint entries.

use ranges::Ranges;

let mut ranges = Ranges::from(..6);
ranges.insert(7..=7);
ranges.insert(9..=9);
ranges.insert(15..);
assert_eq!(
    format!("{}", ranges),
    "[-2147483648, 6) \u{222a} {7, 9} \u{222a} [15, 2147483647]"
);

impl<T: Eq + Domain> Eq for Ranges<T>[src]

impl<T: Domain, U> From<U> for Ranges<T> where
    U: Into<GenericRange<T>>, 
[src]

impl<T: Domain, U> From<Vec<U>> for Ranges<T> where
    U: Into<GenericRange<T>>, 
[src]

impl<T: Domain> FromIterator<GenericRange<T>> for Ranges<T>[src]

impl<T: Hash + Domain> Hash for Ranges<T>[src]

impl<T: LowerExp + Domain> LowerExp for Ranges<T>[src]

Non-Debug formatting uses interval notation and formats the bound values according to the given formatting arguments.

Note

Unless disabled by using the - formatting argument, a whitespace will be printed after the bound separator. Because there is currently no use for -, it will have no effect on the underlying bound values. This might change if requested or core/std makes use of it.

Examples

Single entries. These are formatted like a single GenericRange.

use ranges::Ranges;

assert_eq!(format!("{}", Ranges::from(1..2)), "{1}");
assert_eq!(format!("{}", Ranges::from(1..=2)), "[1, 2]");
assert_eq!(format!("{}", Ranges::from(42..)), "[42, 2147483647]");
assert_eq!(format!("{:03}", Ranges::from(1..2)), "{001}");
assert_eq!(format!("{:02X}", Ranges::from(1..=10)), "[01, 0A]");
assert_eq!(format!("{:-#}", Ranges::from(42..=100)), "[42,100]");

Multiple entries. is used for an empty set and is used to concatenate disjoint entries.

use ranges::Ranges;

let mut ranges = Ranges::from(..6);
ranges.insert(7..=7);
ranges.insert(9..=9);
ranges.insert(15..);
assert_eq!(
    format!("{}", ranges),
    "[-2147483648, 6) \u{222a} {7, 9} \u{222a} [15, 2147483647]"
);

impl<T: LowerHex + Domain> LowerHex for Ranges<T>[src]

Non-Debug formatting uses interval notation and formats the bound values according to the given formatting arguments.

Note

Unless disabled by using the - formatting argument, a whitespace will be printed after the bound separator. Because there is currently no use for -, it will have no effect on the underlying bound values. This might change if requested or core/std makes use of it.

Examples

Single entries. These are formatted like a single GenericRange.

use ranges::Ranges;

assert_eq!(format!("{}", Ranges::from(1..2)), "{1}");
assert_eq!(format!("{}", Ranges::from(1..=2)), "[1, 2]");
assert_eq!(format!("{}", Ranges::from(42..)), "[42, 2147483647]");
assert_eq!(format!("{:03}", Ranges::from(1..2)), "{001}");
assert_eq!(format!("{:02X}", Ranges::from(1..=10)), "[01, 0A]");
assert_eq!(format!("{:-#}", Ranges::from(42..=100)), "[42,100]");

Multiple entries. is used for an empty set and is used to concatenate disjoint entries.

use ranges::Ranges;

let mut ranges = Ranges::from(..6);
ranges.insert(7..=7);
ranges.insert(9..=9);
ranges.insert(15..);
assert_eq!(
    format!("{}", ranges),
    "[-2147483648, 6) \u{222a} {7, 9} \u{222a} [15, 2147483647]"
);

impl<T: Domain> Not for Ranges<T>[src]

This calls self.invert().

type Output = Self

The resulting type after applying the ! operator.

impl<T: Octal + Domain> Octal for Ranges<T>[src]

Non-Debug formatting uses interval notation and formats the bound values according to the given formatting arguments.

Note

Unless disabled by using the - formatting argument, a whitespace will be printed after the bound separator. Because there is currently no use for -, it will have no effect on the underlying bound values. This might change if requested or core/std makes use of it.

Examples

Single entries. These are formatted like a single GenericRange.

use ranges::Ranges;

assert_eq!(format!("{}", Ranges::from(1..2)), "{1}");
assert_eq!(format!("{}", Ranges::from(1..=2)), "[1, 2]");
assert_eq!(format!("{}", Ranges::from(42..)), "[42, 2147483647]");
assert_eq!(format!("{:03}", Ranges::from(1..2)), "{001}");
assert_eq!(format!("{:02X}", Ranges::from(1..=10)), "[01, 0A]");
assert_eq!(format!("{:-#}", Ranges::from(42..=100)), "[42,100]");

Multiple entries. is used for an empty set and is used to concatenate disjoint entries.

use ranges::Ranges;

let mut ranges = Ranges::from(..6);
ranges.insert(7..=7);
ranges.insert(9..=9);
ranges.insert(15..);
assert_eq!(
    format!("{}", ranges),
    "[-2147483648, 6) \u{222a} {7, 9} \u{222a} [15, 2147483647]"
);

impl<T: PartialEq + Domain> PartialEq<Ranges<T>> for Ranges<T>[src]

impl<T: Pointer + Domain> Pointer for Ranges<T>[src]

Non-Debug formatting uses interval notation and formats the bound values according to the given formatting arguments.

Note

Unless disabled by using the - formatting argument, a whitespace will be printed after the bound separator. Because there is currently no use for -, it will have no effect on the underlying bound values. This might change if requested or core/std makes use of it.

Examples

Single entries. These are formatted like a single GenericRange.

use ranges::Ranges;

assert_eq!(format!("{}", Ranges::from(1..2)), "{1}");
assert_eq!(format!("{}", Ranges::from(1..=2)), "[1, 2]");
assert_eq!(format!("{}", Ranges::from(42..)), "[42, 2147483647]");
assert_eq!(format!("{:03}", Ranges::from(1..2)), "{001}");
assert_eq!(format!("{:02X}", Ranges::from(1..=10)), "[01, 0A]");
assert_eq!(format!("{:-#}", Ranges::from(42..=100)), "[42,100]");

Multiple entries. is used for an empty set and is used to concatenate disjoint entries.

use ranges::Ranges;

let mut ranges = Ranges::from(..6);
ranges.insert(7..=7);
ranges.insert(9..=9);
ranges.insert(15..);
assert_eq!(
    format!("{}", ranges),
    "[-2147483648, 6) \u{222a} {7, 9} \u{222a} [15, 2147483647]"
);

impl<T: Domain> StructuralEq for Ranges<T>[src]

impl<T: Domain> StructuralPartialEq for Ranges<T>[src]

impl<T, I> Sub<I> for Ranges<T> where
    I: Into<GenericRange<T>>,
    T: Domain
[src]

This calls self.remove(other).

type Output = Self

The resulting type after applying the - operator.

impl<T: Domain> Sub<Ranges<T>> for Ranges<T>[src]

type Output = Self

The resulting type after applying the - operator.

impl<T, I> SubAssign<I> for Ranges<T> where
    I: Into<GenericRange<T>>,
    T: Domain
[src]

This calls self.remove(other).

impl<T: Domain> SubAssign<Ranges<T>> for Ranges<T>[src]

This calls self.difference(other) and replaces self with the result.

impl<T: UpperExp + Domain> UpperExp for Ranges<T>[src]

Non-Debug formatting uses interval notation and formats the bound values according to the given formatting arguments.

Note

Unless disabled by using the - formatting argument, a whitespace will be printed after the bound separator. Because there is currently no use for -, it will have no effect on the underlying bound values. This might change if requested or core/std makes use of it.

Examples

Single entries. These are formatted like a single GenericRange.

use ranges::Ranges;

assert_eq!(format!("{}", Ranges::from(1..2)), "{1}");
assert_eq!(format!("{}", Ranges::from(1..=2)), "[1, 2]");
assert_eq!(format!("{}", Ranges::from(42..)), "[42, 2147483647]");
assert_eq!(format!("{:03}", Ranges::from(1..2)), "{001}");
assert_eq!(format!("{:02X}", Ranges::from(1..=10)), "[01, 0A]");
assert_eq!(format!("{:-#}", Ranges::from(42..=100)), "[42,100]");

Multiple entries. is used for an empty set and is used to concatenate disjoint entries.

use ranges::Ranges;

let mut ranges = Ranges::from(..6);
ranges.insert(7..=7);
ranges.insert(9..=9);
ranges.insert(15..);
assert_eq!(
    format!("{}", ranges),
    "[-2147483648, 6) \u{222a} {7, 9} \u{222a} [15, 2147483647]"
);

impl<T: UpperHex + Domain> UpperHex for Ranges<T>[src]

Non-Debug formatting uses interval notation and formats the bound values according to the given formatting arguments.

Note

Unless disabled by using the - formatting argument, a whitespace will be printed after the bound separator. Because there is currently no use for -, it will have no effect on the underlying bound values. This might change if requested or core/std makes use of it.

Examples

Single entries. These are formatted like a single GenericRange.

use ranges::Ranges;

assert_eq!(format!("{}", Ranges::from(1..2)), "{1}");
assert_eq!(format!("{}", Ranges::from(1..=2)), "[1, 2]");
assert_eq!(format!("{}", Ranges::from(42..)), "[42, 2147483647]");
assert_eq!(format!("{:03}", Ranges::from(1..2)), "{001}");
assert_eq!(format!("{:02X}", Ranges::from(1..=10)), "[01, 0A]");
assert_eq!(format!("{:-#}", Ranges::from(42..=100)), "[42,100]");

Multiple entries. is used for an empty set and is used to concatenate disjoint entries.

use ranges::Ranges;

let mut ranges = Ranges::from(..6);
ranges.insert(7..=7);
ranges.insert(9..=9);
ranges.insert(15..);
assert_eq!(
    format!("{}", ranges),
    "[-2147483648, 6) \u{222a} {7, 9} \u{222a} [15, 2147483647]"
);

Auto Trait Implementations

impl<T> Send for Ranges<T> where
    T: Send

impl<T> Sync for Ranges<T> where
    T: Sync

impl<T> Unpin for Ranges<T> where
    T: Unpin

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<!> for T[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.