Trait sorted_collections::sortedset::SortedSetExt
[−]
[src]
pub trait SortedSetExt<T> where
T: Clone + Ord, { type RangeRemove; fn first(&self) -> Option<&T>; fn first_remove(&mut self) -> Option<T>; fn last(&self) -> Option<&T>; fn last_remove(&mut self) -> Option<T>; fn ceiling(&self, elem: &T) -> Option<&T>; fn ceiling_remove(&mut self, elem: &T) -> Option<T>; fn floor(&self, elem: &T) -> Option<&T>; fn floor_remove(&mut self, elem: &T) -> Option<T>; fn higher(&self, elem: &T) -> Option<&T>; fn higher_remove(&mut self, elem: &T) -> Option<T>; fn lower(&self, elem: &T) -> Option<&T>; fn lower_remove(&mut self, elem: &T) -> Option<T>; fn range_remove(
&mut self,
_: Bound<&T>,
to_elem: Bound<&T>
) -> Self::RangeRemove; }
An extension trait for a Set
whose elements have a defined total ordering.
This trait defines convenience methods which take advantage of the set's ordering.
Associated Types
type RangeRemove
A by-value iterator yielding elements within a given range which have just been removed from this set.
Required Methods
fn first(&self) -> Option<&T>
Returns an immutable reference to the first (least) element currently in this set.
Returns None
if this set is empty.
Examples
extern crate "sorted-collections" as sorted_collections; use std::collections::BTreeSet; use sorted_collections::SortedSetExt; fn main() { let set: BTreeSet<u32> = vec![1u32, 2, 3, 4, 5].into_iter().collect(); assert_eq!(set.first().unwrap(), &1u32); }
fn first_remove(&mut self) -> Option<T>
Removes and returns the first (least) element currently in this set.
Returns None
if this set is empty.
Examples
extern crate "sorted-collections" as sorted_collections; use std::collections::BTreeSet; use sorted_collections::SortedSetExt; fn main() { let mut set: BTreeSet<u32> = vec![1u32, 2, 3, 4, 5].into_iter().collect(); assert_eq!(set.first_remove().unwrap(), 1u32); assert_eq!(set.into_iter().collect::<Vec<u32>>(), vec![2u32, 3, 4, 5]); }
fn last(&self) -> Option<&T>
Returns an immutable reference to the last (greatest) element currently in this set.
Returns None
if this set is empty.
Examples
extern crate "sorted-collections" as sorted_collections; use std::collections::BTreeSet; use sorted_collections::SortedSetExt; fn main() { let set: BTreeSet<u32> = vec![1u32, 2, 3, 4, 5].into_iter().collect(); assert_eq!(set.last().unwrap(), &5u32); }
fn last_remove(&mut self) -> Option<T>
Removes and returns the last (greatest) element currently in this set.
Returns None
if this set is empty.
Examples
extern crate "sorted-collections" as sorted_collections; use std::collections::BTreeSet; use sorted_collections::SortedSetExt; fn main() { let mut set: BTreeSet<u32> = vec![1u32, 2, 3, 4, 5].into_iter().collect(); assert_eq!(set.last_remove().unwrap(), 5u32); assert_eq!(set.into_iter().collect::<Vec<u32>>(), vec![1u32, 2, 3, 4]); }
fn ceiling(&self, elem: &T) -> Option<&T>
Returns an immutable reference to the least element in this set greater than or equal to elem
.
Returns None
if there is no such element.
Examples
extern crate "sorted-collections" as sorted_collections; use std::collections::BTreeSet; use sorted_collections::SortedSetExt; fn main() { let set: BTreeSet<u32> = vec![1u32, 2, 3, 4, 5].into_iter().collect(); assert_eq!(set.ceiling(&3).unwrap(), &3u32); }
fn ceiling_remove(&mut self, elem: &T) -> Option<T>
Removes and returns the least element in this set greater than or equal to elem
.
Returns None
if there is no such element.
Examples
extern crate "sorted-collections" as sorted_collections; use std::collections::BTreeSet; use sorted_collections::SortedSetExt; fn main() { let mut set: BTreeSet<u32> = vec![1u32, 2, 3, 4, 5].into_iter().collect(); assert_eq!(set.ceiling_remove(&3).unwrap(), 3u32); assert_eq!(set.into_iter().collect::<Vec<u32>>(), vec![1u32, 2, 4, 5]); }
fn floor(&self, elem: &T) -> Option<&T>
Returns an immutable reference to the greatest element in this set less than or equal to elem
.
Returns None
if there is no such element.
Examples
extern crate "sorted-collections" as sorted_collections; use std::collections::BTreeSet; use sorted_collections::SortedSetExt; fn main() { let set: BTreeSet<u32> = vec![1u32, 2, 3, 4, 5].into_iter().collect(); assert_eq!(set.floor(&3).unwrap(), &3u32); }
fn floor_remove(&mut self, elem: &T) -> Option<T>
Removes and returns the greatest element in this set less than or equal to elem
.
Returns None
if there is no such element.
Examples
extern crate "sorted-collections" as sorted_collections; use std::collections::BTreeSet; use sorted_collections::SortedSetExt; fn main() { let mut set: BTreeSet<u32> = vec![1u32, 2, 3, 4, 5].into_iter().collect(); assert_eq!(set.floor_remove(&3).unwrap(), 3u32); assert_eq!(set.into_iter().collect::<Vec<u32>>(), vec![1u32, 2, 4, 5]); }
fn higher(&self, elem: &T) -> Option<&T>
Returns an immutable reference to the least element in this set strictly greater than elem
.
Returns None
if there is no such element.
Examples
extern crate "sorted-collections" as sorted_collections; use std::collections::BTreeSet; use sorted_collections::SortedSetExt; fn main() { let set: BTreeSet<u32> = vec![1u32, 2, 3, 4, 5].into_iter().collect(); assert_eq!(set.higher(&3).unwrap(), &4u32); }
fn higher_remove(&mut self, elem: &T) -> Option<T>
Removes and returns the least element in this set strictly greater than elem
.
Returns None
if there is no such element.
Examples
extern crate "sorted-collections" as sorted_collections; use std::collections::BTreeSet; use sorted_collections::SortedSetExt; fn main() { let mut set: BTreeSet<u32> = vec![1u32, 2, 3, 4, 5].into_iter().collect(); assert_eq!(set.higher_remove(&3).unwrap(), 4u32); assert_eq!(set.into_iter().collect::<Vec<u32>>(), vec![1u32, 2, 3, 5]); }
fn lower(&self, elem: &T) -> Option<&T>
Returns an immutable reference to the greatest element in this set strictly less than elem
.
Returns None
if there is no such element.
Examples
extern crate "sorted-collections" as sorted_collections; use std::collections::BTreeSet; use sorted_collections::SortedSetExt; fn main() { let set: BTreeSet<u32> = vec![1u32, 2, 3, 4, 5].into_iter().collect(); assert_eq!(set.lower(&3).unwrap(), &2u32); }
fn lower_remove(&mut self, elem: &T) -> Option<T>
Removes and returns the greatest element in this set strictly less than elem
.
Returns None
if there is no such element.
Examples
extern crate "sorted-collections" as sorted_collections; use std::collections::BTreeSet; use sorted_collections::SortedSetExt; fn main() { let mut set: BTreeSet<u32> = vec![1u32, 2, 3, 4, 5].into_iter().collect(); assert_eq!(set.lower_remove(&3).unwrap(), 2u32); assert_eq!(set.into_iter().collect::<Vec<u32>>(), vec![1u32, 3, 4, 5]); }
fn range_remove(
&mut self,
_: Bound<&T>,
to_elem: Bound<&T>
) -> Self::RangeRemove
&mut self,
_: Bound<&T>,
to_elem: Bound<&T>
) -> Self::RangeRemove
Removes the elements of this set in the range starting at from_elem
and ending at
to_elem
, and returns a double-ended by-value iterator yielding the removed elements.
If from_elem
is Unbounded
, then it will be treated as "negative infinity", and
if to_elem
is Unbounded
, then it will be treated as "positive infinity". Thus,
range_remove(Unbounded, Unbounded)
will clear the set and return a by-value
iterator over all of the elements which were in it.
Examples
extern crate "sorted-collections" as sorted_collections; use std::collections::Bound::{Excluded, Included}; use std::collections::BTreeSet; use sorted_collections::SortedSetExt; fn main() { let mut set: BTreeSet<u32> = vec![1u32, 2, 3, 4, 5].into_iter().collect(); assert_eq!(set.range_remove(Included(&2), Excluded(&4)).collect::<Vec<u32>>(), vec![2u32, 3]); assert_eq!(set.into_iter().collect::<Vec<u32>>(), vec![1u32, 4, 5]); }
Implementations on Foreign Types
impl<'a, T> SortedSetExt<T> for BTreeSet<T> where
T: Clone + Ord,
[src]
T: Clone + Ord,
type RangeRemove = BTreeSetRangeRemove<T>
fn first(&self) -> Option<&T>
[src]
fn first_remove(&mut self) -> Option<T>
[src]
fn last(&self) -> Option<&T>
[src]
fn last_remove(&mut self) -> Option<T>
[src]
fn ceiling(&self, elem: &T) -> Option<&T>
[src]
fn ceiling_remove(&mut self, elem: &T) -> Option<T>
[src]
fn floor(&self, elem: &T) -> Option<&T>
[src]
fn floor_remove(&mut self, elem: &T) -> Option<T>
[src]
fn higher(&self, elem: &T) -> Option<&T>
[src]
fn higher_remove(&mut self, elem: &T) -> Option<T>
[src]
fn lower(&self, elem: &T) -> Option<&T>
[src]
fn lower_remove(&mut self, elem: &T) -> Option<T>
[src]
ⓘImportant traits for BTreeSetRangeRemove<T>fn range_remove(
&mut self,
from_elem: Bound<&T>,
to_elem: Bound<&T>
) -> BTreeSetRangeRemove<T>
[src]
&mut self,
from_elem: Bound<&T>,
to_elem: Bound<&T>
) -> BTreeSetRangeRemove<T>