[][src]Struct range_collections::range_set::RangeSet

pub struct RangeSet<T, A: Array<Item = T> = [T; 2]> { /* fields omitted */ }

A set of non-overlapping ranges

let mut a: RangeSet<i32> = RangeSet::from(10..);
let b: RangeSet<i32> = RangeSet::from(1..5);

a |= b;
let r = !a;

A data structure to represent a set of non-overlapping ranges of element type T: Ord. It uses a SmallVec<T> of sorted boundaries internally.

It can represent not just finite ranges but also ranges with unbounded start or end. Because it can represent infinite ranges, it can also represent the set of all elements, and therefore all boolean operations including negation.

It does not put any constraints on the element type for requriring an Ord instance. Adjacent ranges will be merged.

It provides very fast operations for set operations (&, |, ^) as well as for intersection tests (is_disjoint, is_subset).

In addition to the fast set operations that produce a new range set, it also supports the equivalent in-place operations.

Complexity

Complexity is given separately for the number of comparisons and the number of copies, since sometimes you have a comparison operation that is basically free (any of the primitive types), whereas sometimes you have a comparison operation that is many orders of magnitude more expensive than a copy (long strings, arbitrary precision integers, ...)

Number of comparisons

operationbestworstremark
negation1      1       
unionO(log(N))O(N)binary merge
intersectionO(log(N))O(N)binary merge
differenceO(log(N))O(N)binary merge
xorO(log(N))O(N)binary merge
membershipO(log(N))O(log(N))binary search
is_disjointO(log(N))O(N)binary merge with cutoff
is_subsetO(log(N))O(N)binary merge with cutoff

Number of copies

For creating new sets, obviously there needs to be at least one copy for each element of the result set, so the complexity is always O(N). For in-place operations it gets more interesting. In case the number of elements of the result being identical to the number of existing elements, there will be no copies and no allocations.

E.g. if the result just has some of the ranges of the left hand side extended or truncated, but the same number of boundaries, there will be no allocations and no copies except for the changed boundaries themselves.

If the result has fewer boundaries than then lhs, there will be some copying but no allocations. Only if the result is larger than the capacity of the underlying vector of the lhs will there be allocations.

operationbestworst
negation1      1       
union1O(N)
intersection1O(N)
difference1O(N)
xor1O(N)

Testing

Testing is done by some simple smoke tests as well as quickcheck tests of the algebraic properties of the boolean operations.

Implementations

impl<T, A: Array<Item = T>> RangeSet<T, A>[src]

pub fn iter(&self) -> Iter<'_, T>

Notable traits for Iter<'a, T>

impl<'a, T> Iterator for Iter<'a, T> type Item = (Bound<&'a T>, Bound<&'a T>);
[src]

iterate over all ranges in this range set

pub fn boundaries(&self) -> &SmallVec<A>[src]

boundaries in this range set

pub fn into_inner(self) -> SmallVec<A>[src]

get the boundaries in this range set as a SmallVec

pub fn empty() -> Self[src]

the empty range set

pub fn all() -> Self[src]

a range set containing all values

pub fn constant(value: bool) -> Self[src]

a range set with a constant value everywhere

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

true if the range set is empty

pub fn is_all(&self) -> bool[src]

true if the range set contains all values

impl<T: Ord, A: Array<Item = T>> RangeSet<T, A>[src]

pub fn is_disjoint(&self, that: &Self) -> bool[src]

true if this range set is disjoint from another range set

pub fn is_superset(&self, that: &Self) -> bool[src]

true if this range set is a superset of another range set

A range set is considered to be a superset of itself

pub fn is_subset(&self, that: &Self) -> bool[src]

true if this range set is a subset of another range set

A range set is considered to be a subset of itself

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

true if the value is contained in the range set

Trait Implementations

impl<T: Ord + Clone, A: Array<Item = T>, '_> BitAnd<&'_ RangeSet<T, A>> for &'_ RangeSet<T, A>[src]

compute the intersection of this range set with another, producing a new range set

∀ t ∈ T, r(t) = a(t) & b(t)

type Output = RangeSet<T, A>

The resulting type after applying the & operator.

impl<T: Ord, A: Array<Item = T>> BitAndAssign<RangeSet<T, A>> for RangeSet<T, A>[src]

impl<T: Ord + Clone, A: Array<Item = T>, '_> BitOr<&'_ RangeSet<T, A>> for &'_ RangeSet<T, A>[src]

compute the union of this range set with another, producing a new range set

∀ t ∈ T, r(t) = a(t) | b(t)

type Output = RangeSet<T, A>

The resulting type after applying the | operator.

impl<T: Ord, A: Array<Item = T>> BitOrAssign<RangeSet<T, A>> for RangeSet<T, A>[src]

impl<T: Ord + Clone, A: Array<Item = T>, '_> BitXor<&'_ RangeSet<T, A>> for &'_ RangeSet<T, A>[src]

compute the exclusive or of this range set with another, producing a new range set

∀ t ∈ T, r(t) = a(t) ^ b(t)

type Output = RangeSet<T, A>

The resulting type after applying the ^ operator.

impl<T: Ord, A: Array<Item = T>> BitXorAssign<RangeSet<T, A>> for RangeSet<T, A>[src]

impl<T: Clone, A: Clone + Array<Item = T>> Clone for RangeSet<T, A>[src]

impl<T: Debug, A: Array<Item = T>> Debug for RangeSet<T, A>[src]

impl<'de, T: Deserialize<'de> + Ord, A: Array<Item = T>> Deserialize<'de> for RangeSet<T, A>[src]

impl<T: Eq, A: Eq + Array<Item = T>> Eq for RangeSet<T, A>[src]

impl<T: Ord, A: Array<Item = T>> From<Range<T>> for RangeSet<T, A>[src]

impl<T: Ord, A: Array<Item = T>> From<RangeFrom<T>> for RangeSet<T, A>[src]

impl<T: Ord, A: Array<Item = T>> From<RangeTo<T>> for RangeSet<T, A>[src]

impl<T, A: Array<Item = T>> From<bool> for RangeSet<T, A>[src]

impl<T: Ord + Clone, A: Array<Item = T>> Not for RangeSet<T, A>[src]

compute the negation of this range set

∀ t ∈ T, r(t) = !a(t)

type Output = RangeSet<T, A>

The resulting type after applying the ! operator.

impl<T: Ord + Clone, A: Array<Item = T>, '_> Not for &'_ RangeSet<T, A>[src]

compute the negation of this range set

∀ t ∈ T, r(t) = !a(t)

type Output = RangeSet<T, A>

The resulting type after applying the ! operator.

impl<T: PartialEq, A: PartialEq + Array<Item = T>> PartialEq<RangeSet<T, A>> for RangeSet<T, A>[src]

impl<T: Serialize, A: Array<Item = T>> Serialize for RangeSet<T, A>[src]

impl<T, A: Array<Item = T>> StructuralEq for RangeSet<T, A>[src]

impl<T, A: Array<Item = T>> StructuralPartialEq for RangeSet<T, A>[src]

impl<T: Ord + Clone, A: Array<Item = T>, '_> Sub<&'_ RangeSet<T, A>> for &'_ RangeSet<T, A>[src]

compute the difference of this range set with another, producing a new range set

∀ t ∈ T, r(t) = a(t) & !b(t)

type Output = RangeSet<T, A>

The resulting type after applying the - operator.

impl<T: Ord, A: Array<Item = T>> SubAssign<RangeSet<T, A>> for RangeSet<T, A>[src]

Auto Trait Implementations

impl<T, A> RefUnwindSafe for RangeSet<T, A> where
    A: RefUnwindSafe,
    T: RefUnwindSafe

impl<T, A> Send for RangeSet<T, A> where
    T: Send

impl<T, A> Sync for RangeSet<T, A> where
    A: Sync

impl<T, A> Unpin for RangeSet<T, A> where
    A: Unpin

impl<T, A> UnwindSafe for RangeSet<T, A> where
    A: UnwindSafe,
    T: RefUnwindSafe

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> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[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, 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.