pub enum OrderedSet {
Interval {
start: u32,
end: u32,
},
Sorted(Arc<[u32]>),
}Expand description
Ordered set of indices — either a contiguous interval or sorted array.
The Interval variant provides O(1) membership tests for contiguous ranges.
The Sorted variant provides O(log n) membership tests for arbitrary selections.
Variants§
Interval
Contiguous range [start, end) — O(1) membership test
Sorted(Arc<[u32]>)
Sorted unique indices — O(log n) membership test
Implementations§
Source§impl OrderedSet
impl OrderedSet
Sourcepub fn from_sorted(indices: Vec<u32>) -> Self
pub fn from_sorted(indices: Vec<u32>) -> Self
Create a Sorted set from a Vec<u32>.
The input must already be sorted and contain no duplicates.
This function panics if either condition is violated, keeping the
invariant that Sorted always holds valid data.
If you need to accept arbitrary input, sort and dedup before calling:
let mut v = vec![3u32, 1, 2, 1];
v.sort_unstable();
v.dedup();
let set = OrderedSet::from_sorted(v);Sourcepub fn iter(&self) -> impl Iterator<Item = u32> + '_
pub fn iter(&self) -> impl Iterator<Item = u32> + '_
Iterate over the elements of this set in ascending order.
Sourcepub fn union(&self, other: &Self) -> Self
pub fn union(&self, other: &Self) -> Self
Compute the union of this set and other.
Uses a merge-style algorithm on two sorted iterators — O(n + m).
Returns an OrderedSet::Sorted.
Sourcepub fn intersection(&self, other: &Self) -> Self
pub fn intersection(&self, other: &Self) -> Self
Compute the intersection of this set and other.
Uses a merge-style algorithm — O(n + m).
Returns an OrderedSet::Sorted.
Sourcepub fn difference(&self, other: &Self) -> Self
pub fn difference(&self, other: &Self) -> Self
Compute the set difference self \ other (elements in self but not other).
Uses a merge-style algorithm — O(n + m).
Returns an OrderedSet::Sorted.
Trait Implementations§
Source§impl Clone for OrderedSet
impl Clone for OrderedSet
Source§fn clone(&self) -> OrderedSet
fn clone(&self) -> OrderedSet
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for OrderedSet
impl Debug for OrderedSet
Source§impl PartialEq for OrderedSet
impl PartialEq for OrderedSet
impl StructuralPartialEq for OrderedSet
Auto Trait Implementations§
impl Freeze for OrderedSet
impl RefUnwindSafe for OrderedSet
impl Send for OrderedSet
impl Sync for OrderedSet
impl Unpin for OrderedSet
impl UnsafeUnpin for OrderedSet
impl UnwindSafe for OrderedSet
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more