Struct range_union_find::IntRangeUnionFind [−][src]
pub struct IntRangeUnionFind<T> where
T: PrimInt, { /* fields omitted */ }Expand description
Struct representing a union of integer ranges.
Implementations
Constructs a new IntRangeUnionFind object.
Returns a tuple describing the range the element is in, as well as its location.
The range_id is a count of which range the element is in.
The enum indicates where the element is in the range, with
(Exterior,i) meaning the exterior region before the i’th range.
See ContainedType for an explanation of the enum values.
If the element is in a single-element range of the form a..=a,
the enum will not be Exterior, but its exact value is otherwise unspecified.
Example
let mut range_obj = IntRangeUnionFind::new(); range_obj.insert_range(&(10..20)); assert_eq!(range_obj.has_element_enum(&0), (ContainedType::Exterior, 0)); assert_eq!(range_obj.has_element_enum(&10), (ContainedType::Start, 0)); assert_eq!(range_obj.has_element_enum(&15), (ContainedType::Interior, 0)); assert_eq!(range_obj.has_element_enum(&19), (ContainedType::End, 0)); assert_eq!(range_obj.has_element_enum(&25), (ContainedType::Exterior, 1));
let mut range_obj = IntRangeUnionFind::new(); range_obj.insert_range(&(8..=8)); let (contain_enum, contain_id) = range_obj.has_element_enum(&8); assert_ne!(contain_enum, ContainedType::Exterior); assert_eq!(contain_id, 0);
Returns whether the element is contained in the stored ranges.
Returns false when Self::has_element_enum returns a
ContainedType::Exterior enum, and true otherwise.
pub fn has_range<U: RangeBounds<T>>(
&self,
range: &U
) -> Result<OverlapType<T>, RangeOperationError>
pub fn has_range<U: RangeBounds<T>>(
&self,
range: &U
) -> Result<OverlapType<T>, RangeOperationError>Returns how the given range overlaps with the stored ranges.
See OverlapType for a description of the enum values.
Example
let mut range_obj = IntRangeUnionFind::new(); range_obj.insert_range(&(10..20)); range_obj.insert_range(&(-20..-10)); assert_eq!(range_obj.has_range(&(15..17))?, OverlapType::Contained); assert_eq!(range_obj.has_range(&(-5..5))?, OverlapType::Disjoint); assert_eq!(range_obj.has_range(&(0..20))?, OverlapType::Partial(10)); assert_eq!(range_obj.has_range(&(-15..15))?, OverlapType::Partial(10));
Errors
Returns RangeOperationError if given range is invalid.
pub fn has_range_pair(
&self,
start: &T,
end: &T
) -> Result<OverlapType<T>, RangeOperationError>
pub fn has_range_pair(
&self,
start: &T,
end: &T
) -> Result<OverlapType<T>, RangeOperationError>Functions like Self::has_range given input start..=end.
pub fn find_range_with_element(
&self,
element: &T
) -> Result<impl RangeBounds<T>, impl RangeBounds<T>>
pub fn find_range_with_element(
&self,
element: &T
) -> Result<impl RangeBounds<T>, impl RangeBounds<T>>Returns the range the element is in.
If the element is in a range, return Ok(range_with_element).
Otherwise, return Err(range_between_stored_ranges).
Warning: the impl RangeBounds<T> object does not include a Debug impl, so unwrap and unwrap_err cannot be used on the returned result.
Example
let mut range_obj = IntRangeUnionFind::<i32>::new(); range_obj.insert_range(&(10..=20)); let one_result = range_obj.find_range_with_element(&1); assert!(match one_result { Err(one_err) => { assert_eq!(one_err.start_bound(), Bound::Unbounded); assert_eq!(one_err.end_bound(), Bound::Excluded(&10)); true }, Ok(_) => false }); let twelve_result = range_obj.find_range_with_element(&12); assert!(match twelve_result { Ok(twelve_range) => { assert_eq!(twelve_range.start_bound(), Bound::Included(&10)); assert_eq!(twelve_range.end_bound(), Bound::Included(&20)); true }, Err(_) => false }); let seventy_result = range_obj.find_range_with_element(&70); assert!(match seventy_result { Err(seventy_err) => { assert_eq!(seventy_err.start_bound(), Bound::Excluded(&20)); assert_eq!(seventy_err.end_bound(), Bound::Unbounded); true }, Ok(_) => false });
pub fn insert_range<U: RangeBounds<T>>(
&mut self,
range: &U
) -> Result<(), RangeOperationError>
pub fn insert_range<U: RangeBounds<T>>(
&mut self,
range: &U
) -> Result<(), RangeOperationError>Inserts the range into the set of ranges.
Errors
Returns RangeOperationError if the given range is invalid.
Functions like Self::insert_range given input start..=end.
pub fn remove_range<U: RangeBounds<T>>(
&mut self,
range: &U
) -> Result<(), RangeOperationError>
pub fn remove_range<U: RangeBounds<T>>(
&mut self,
range: &U
) -> Result<(), RangeOperationError>Removes the range from the set of ranges.
Errors
Returns RangeOperationError if the given range is invalid.
Functions like Self::remove_range given input start..=end.
Creates a collection of RangeInclusive with element type T from a IntRangeUnionFind object.
Converts a IntRangeUnionFind object into a collection of RangeInclusive with element type T.
Trait Implementations
Computes the union of the two IntRangeUnionFind objects.
type Output = IntRangeUnionFind<T>
type Output = IntRangeUnionFind<T>The resulting type after applying the & operator.
Computes the union of the two IntRangeUnionFind objects.
type Output = IntRangeUnionFind<T>
type Output = IntRangeUnionFind<T>The resulting type after applying the | operator.
type Output = IntRangeUnionFind<T>
type Output = IntRangeUnionFind<T>The resulting type after applying the ^ operator.
Performs the ^ operation. Read more
Returns the “default value” for a type. Read more
Calls Self::insert_range for each range in the iterator.
Panics
Panics if any of the range insertions return an Err.
extend_one)Extends a collection with exactly one element.
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
Performs the conversion.
Calls Self::insert_range for each range in the iterator.
Panics
Panics if any of the range insertions return an Err.
This method tests for self and other values to be equal, and is used
by ==. Read more
This method tests for !=.
Subtracts the rhs IntRangeUnionFind object from the lhs one.
type Output = IntRangeUnionFind<T>
type Output = IntRangeUnionFind<T>The resulting type after applying the - operator.
Auto Trait Implementations
impl<T> RefUnwindSafe for IntRangeUnionFind<T> where
T: RefUnwindSafe, impl<T> Send for IntRangeUnionFind<T> where
T: Send, impl<T> Sync for IntRangeUnionFind<T> where
T: Sync, impl<T> Unpin for IntRangeUnionFind<T> where
T: Unpin, impl<T> UnwindSafe for IntRangeUnionFind<T> where
T: UnwindSafe, Blanket Implementations
Mutably borrows from an owned value. Read more