[−][src]Struct sdset::set::SetBuf
An owned, set (akin to String
).
Methods
impl<T> SetBuf<T>
[src]
pub fn new(vec: Vec<T>) -> Result<Self, Error> where
T: Ord,
[src]
T: Ord,
Construct a SetBuf
only if it is sorted and deduplicated.
use sdset::{SetBuf, Error}; let vec = vec![1, 2, 4, 6, 7]; let setbuf = SetBuf::new(vec)?; // this vec is not sorted! let vec = vec![1, 2, 4, 7, 6]; let setbuf = SetBuf::new(vec); assert_eq!(setbuf, Err(Error::NotSort));
pub fn from_dirty(vec: Vec<T>) -> Self where
T: Ord,
[src]
T: Ord,
Construct a SetBuf
from an unsorted and/or
non-deduplicated Vec<T>
.
use sdset::SetBuf; let set = SetBuf::from_dirty(vec![1, 4, 2, 6, 4]); let mut iterator = set.into_iter(); assert_eq!(iterator.next(), Some(1)); assert_eq!(iterator.next(), Some(2)); assert_eq!(iterator.next(), Some(4)); assert_eq!(iterator.next(), Some(6)); assert_eq!(iterator.next(), None);
pub fn new_unchecked(vec: Vec<T>) -> Self
[src]
Construct a SetBuf
without checking it.
use sdset::{SetBuf, Error}; // this vec is not sorted let vec = vec![1, 2, 4, 7, 6]; // but we can still create a SetBuf, so be careful! let setbuf = SetBuf::new_unchecked(vec);
pub fn as_set(&self) -> &Set<T>
[src]
Return the Set
owned by this SetBuf
.
use sdset::{Set, SetBuf, Error}; let vec = vec![1, 2, 4, 6, 7]; let setbuf = SetBuf::new(vec.clone())?; let set = Set::new(&vec)?; assert_eq!(setbuf.as_set(), set);
pub fn into_vec(self) -> Vec<T>
[src]
Return the Vec
inside by this SetBuf
.
use sdset::{SetBuf, Error}; let vec = vec![1, 2, 4, 6, 7]; let setbuf = SetBuf::new(vec)?; let vec = setbuf.into_vec();
pub fn iter(&self) -> Iter<T>
[src]
Returns an iterator over this ordered set.
use sdset::SetBuf; let x = SetBuf::new_unchecked(vec![1, 2, 4]); let mut iterator = x.iter(); assert_eq!(iterator.next(), Some(&1)); assert_eq!(iterator.next(), Some(&2)); assert_eq!(iterator.next(), Some(&4)); assert_eq!(iterator.next(), None);
Methods from Deref<Target = Set<T>>
pub fn range<K: ?Sized, R>(&self, range: R) -> &Self where
K: Ord,
R: RangeBounds<K>,
T: Borrow<K>,
[src]
K: Ord,
R: RangeBounds<K>,
T: Borrow<K>,
Returns a Set
containing all the values in the given range.
This function uses exponential searching internally because it is verified that the elements are ordered.
use std::ops::Bound::{Excluded, Included}; use sdset::{Set, Error}; let set = Set::new(&[1, 2, 4, 6, 7])?; let subset = set.range(2..=6); assert_eq!(subset.as_slice(), &[2, 4, 6]); let subset = set.range(3..5); assert_eq!(subset.as_slice(), &[4]); let subset = set.range((Excluded(&2), Included(&7))); assert_eq!(subset.as_slice(), &[4, 6, 7]);
pub fn exponential_search(&self, elem: &T) -> Result<usize, usize> where
T: Ord,
[src]
T: Ord,
Exponential searches this sorted slice for a given element.
If the value is found then Ok
is returned, containing the index of the matching element;
if the value is not found then Err
is returned, containing the index where a
matching element could be inserted while maintaining sorted order.
See the exponential_search
documentation for more details.
pub fn exponential_search_by<F>(&self, f: F) -> Result<usize, usize> where
F: FnMut(&T) -> Ordering,
[src]
F: FnMut(&T) -> Ordering,
Binary searches this sorted slice with a comparator function.
The comparator function should implement an order consistent with the sort order of
the underlying slice, returning an order code that indicates whether its argument
is Less
, Equal
or Greater
the desired target.
If the value is found then Ok
is returned, containing the index of the matching element;
if the value is not found then Err
is returned, containing the index where a
matching element could be inserted while maintaining sorted order.
See the exponential_search_by
documentation for more details.
pub fn exponential_search_by_key<B, F>(
&self,
b: &B,
f: F
) -> Result<usize, usize> where
F: FnMut(&T) -> B,
B: Ord,
[src]
&self,
b: &B,
f: F
) -> Result<usize, usize> where
F: FnMut(&T) -> B,
B: Ord,
Binary searches this sorted slice with a key extraction function.
Assumes that the slice is sorted by the key.
If the value is found then Ok
is returned, containing the index of the matching element;
if the value is not found then Err
is returned, containing the index where a
matching element could be inserted while maintaining sorted order.
See the exponential_search_by
documentation for more details.
pub fn contains(&self, x: &T) -> bool where
T: Ord,
[src]
T: Ord,
Returns true
if the set contains an element with the given value.
This function uses exponential searching internally because it is verified that the elements are ordered.
use sdset::{Set, Error}; let slice = &[1, 2, 4, 6, 7]; let set = Set::new(slice)?; assert!(set.contains(&4));
pub fn to_set_buf(&self) -> SetBuf<T> where
T: Clone,
[src]
T: Clone,
Construct the owning version of the Set
.
use sdset::{Set, SetBuf, Error}; let set = Set::new(&[1, 2, 4, 6, 7])?; let setbuf: SetBuf<_> = set.to_set_buf();
pub fn as_slice(&self) -> &[T]
[src]
Return the slice "inside" of this Set
.
use sdset::{Set, Error}; let slice = &[1, 2, 4, 6, 7]; let set = Set::new(slice)?; assert_eq!(set.as_slice(), slice);
pub fn iter(&self) -> Iter<T>
[src]
Returns an iterator over this ordered set.
use sdset::Set; let x = Set::new_unchecked(&[1, 2, 4]); let mut iterator = x.iter(); assert_eq!(iterator.next(), Some(&1)); assert_eq!(iterator.next(), Some(&2)); assert_eq!(iterator.next(), Some(&4)); assert_eq!(iterator.next(), None);
Trait Implementations
impl<T> AsRef<Set<T>> for SetBuf<T>
[src]
impl<T> AsRef<[T]> for SetBuf<T>
[src]
impl<T> IntoIterator for SetBuf<T>
[src]
type Item = T
The type of the elements being iterated over.
type IntoIter = IntoIter<Self::Item>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<T: Clone> Clone for SetBuf<T>
[src]
impl<T> Default for SetBuf<T>
[src]
impl<T: Eq> Eq for SetBuf<T>
[src]
impl<T: Ord> Ord for SetBuf<T>
[src]
fn cmp(&self, other: &SetBuf<T>) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
1.21.0[src]
fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<T: PartialEq> PartialEq<SetBuf<T>> for SetBuf<T>
[src]
impl<T: PartialOrd> PartialOrd<SetBuf<T>> for SetBuf<T>
[src]
fn partial_cmp(&self, other: &SetBuf<T>) -> Option<Ordering>
[src]
fn lt(&self, other: &SetBuf<T>) -> bool
[src]
fn le(&self, other: &SetBuf<T>) -> bool
[src]
fn gt(&self, other: &SetBuf<T>) -> bool
[src]
fn ge(&self, other: &SetBuf<T>) -> bool
[src]
impl<T> Deref for SetBuf<T>
[src]
impl<T: Debug> Debug for SetBuf<T>
[src]
impl<T: Hash> Hash for SetBuf<T>
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T> StructuralPartialEq for SetBuf<T>
[src]
impl<T> StructuralEq for SetBuf<T>
[src]
impl<T> Borrow<Set<T>> for SetBuf<T>
[src]
Auto Trait Implementations
impl<T> Send for SetBuf<T> where
T: Send,
T: Send,
impl<T> Sync for SetBuf<T> where
T: Sync,
T: Sync,
impl<T> Unpin for SetBuf<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for SetBuf<T> where
T: UnwindSafe,
T: UnwindSafe,
impl<T> RefUnwindSafe for SetBuf<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,