irange
A data structure to store and manipulate ranges of integers with set operations.
A RangeSet holds an arbitrary set of integers as a sorted collection of non-overlapping inclusive ranges, so a set whose values come in runs costs a handful of bounds rather than one entry per value.
Supported types: u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128 and isize.
Installation
[]
= "1.2"
The optional serde feature implements Serialize and Deserialize for RangeSet:
[]
= { = "1.2", = ["serde"] }
Example
use AnyRange;
use RangeSet;
let a = new_from_ranges;
let b = new_from_range;
let union = &a | &b;
assert_eq!;
assert_eq!;
assert_eq!;
// `&RangeSet` is `IntoIterator`, and the iterator is double-ended.
let values: = union.iter.collect;
assert_eq!;
let descending: = union.iter.rev.collect;
assert_eq!;
Operations
n is the total number of ranges involved. The operators take references, like those of std::collections::BTreeSet, so &a | &b is the union of a and b.
| Operation | Operator | Description | Time | Space |
|---|---|---|---|---|
union |
| |
Compute the union with the given RangeSet. |
O(n) |
O(n) |
intersection |
& |
Compute the intersection with the given RangeSet. |
O(n) |
O(n) |
difference |
- |
Compute the difference with the given RangeSet. |
O(n) |
O(n) |
complement |
! |
Compute the complement. | O(n) |
O(n) |
has_intersection |
Return true if there is a common value with the given RangeSet. |
O(n) |
O(1) |
|
contains |
Return true if it contains the given value. |
O(log n) |
O(1) |
|
contains_all |
Return true if it contains the given RangeSet. |
O(n) |
O(1) |
|
is_total |
Return true if it contains all the possible values. |
O(1) |
O(1) |
|
is_empty |
Return true if it does not contain any value. |
O(1) |
O(1) |
See the API documentation for the full list, and CHANGELOG.md for notable changes.
Minimum supported Rust version
irange builds with Rust 1.63 and later. Raising this version is a breaking change.
Enabling the serde feature pulls in serde_derive, whose own dependencies require a more recent compiler.
Contributing
Bug reports and pull requests are welcome, see CONTRIBUTING.md.
License
Licensed under the MIT License.