Expand description
This create provides operations for mathematical intervals. Such intervals include all values between two bounds.
This library supports multiple kinds of intervals. Let’s call E the set of valid values in the interval,
Interval | Constructor | Description |
---|---|---|
[A,B] | Interval::new_closed_closed | left-closed, right-closed |
[A,B) | Interval::new_closed_open | left-closed, right-open |
(A,B) | Interval::new_open_open | left-open, right-open |
(A,B] | Interval::new_open_closed | left-open, right-closed |
(,B] | Interval::new_unbounded_closed | left-unbounded, right-closed |
(,B) | Interval::new_unbounded_open | left-unbounded, right-open |
[A,) | Interval::new_closed_unbounded | left-closed, right-unbounded |
(A,) | Interval::new_open_unbounded | left-open, right-unbounded |
(,) | Interval::doubly_unbounded | doubly unbounded |
empty | Interval::default() | empty |
Any type can be used for the bounds, though operations on the interval depends on the traits that the bound type implements.
Intervals on floats (like any code using float) can be tricky. For
instance, the two intervals [1.0, 100.0)
and [1.0, 100.0 - f32:EPSILON)
are not considered equivalent, since the machine thinks the two upper
bounds have the same value, but one of them is closed and the other is
open.
Although this type is mostly intended to be used when T can be ordered,
it is in fact possible to define intervals using any type. But only a few
functions are then available (like Interval::lower()
,
Interval::upper()
,…)
Given two intervals, and assuming T is orderable, we can compute the following:
[------ A ------]
[----- B -------]
[----------------------] Convex hull
[------) Difference (A - B)
(------] Difference (B - A)
[------) (------] Symmetric difference (A ^ B)
[--------] Intersection (A & B)
Between is empty
[----------------------] Union (A | B)
When the two intervals do not overlap, we can compute:
[---A---] [----B----]
[---------------------] Convex hull
[-------] Difference (A - B)
[---------] Difference (B - A)
[-------] [---------] Symmetric difference (A ^ B)
Intersection (A & B) is empty
(---) Between
Union (A | B) is empty, non contiguous
Macros§
- interval
- This macro lets you create intervals with a syntax closer to what Postgresql provides. There are multiple variants of this macro:
Structs§
- Interval
- An interval of values.
- Interval
Iterator - Interval
Set std
- A sorted list of non-overlapping intervals. There are multiple ways to combine intervals, depending on the chosen policy.
- Joining
std
- Separating
std
Enums§
- Pair
- The result of the difference between two intervals. This might be a single interval, or two (in which case the first one is always the left-most).
- Parse
Error
Traits§
- Bounded
- Nothing
Between - Trait to compute whether intervals are empty.
- Step
- Similar to std::iter::Step, but the latter is unstable and cannot be used in this package. It also doesn’t provide support for starting from lowest value valid for the type for instance.