[][src]Struct sdset::set::Set

#[repr(transparent)]
pub struct Set<T>(_);

Represent a slice which contains types that are sorted and deduplicated (akin to str).

This is an unsized type, meaning that it must always be used behind a pointer like & or Box. For an owned version of this type, see SetBuf.

Methods

impl<T> Set<T>[src]

pub fn new(slice: &[T]) -> Result<&Self, Error> where
    T: Ord
[src]

Construct a Set only if it is sorted and deduplicated.

use sdset::{Set, Error};

let slice = &[1, 2, 4, 6, 7];
let set = Set::new(slice)?;

// this slice is not sorted!
let slice = &[1, 2, 4, 7, 6];
let set = Set::new(slice);

assert_eq!(set, Err(Error::NotSort));

pub fn new_unchecked(slice: &[T]) -> &Self[src]

Construct a Set without checking it.

use sdset::{Set, Error};

// this slice is not sorted
let slice = &[1, 2, 4, 7, 6];

// but we can still create a Set, so be careful!
let set = Set::new_unchecked(slice);

pub fn range<K: ?Sized, R>(&self, range: R) -> &Self where
    K: Ord,
    R: RangeBounds<K>,
    T: Borrow<K>, 
[src]

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]);

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]

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]

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]

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]

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<[T]> for Set<T>[src]

impl<T> AsRef<Set<T>> for Set<T>[src]

impl<T> AsRef<Set<T>> for SetBuf<T>[src]

impl<T> Borrow<Set<T>> for SetBuf<T>[src]

impl<T: Debug> Debug for Set<T>[src]

impl<'_, T> Default for &'_ Set<T>[src]

impl<T> Deref for Set<T>[src]

type Target = [T]

The resulting type after dereferencing.

impl<T: Eq> Eq for Set<T>[src]

impl<T: Hash> Hash for Set<T>[src]

impl<'a, T> IntoIterator for &'a Set<T>[src]

type Item = &'a T

The type of the elements being iterated over.

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?

impl<T: Ord> Ord for Set<T>[src]

impl<T: PartialEq> PartialEq<Set<T>> for Set<T>[src]

impl<T: PartialOrd> PartialOrd<Set<T>> for Set<T>[src]

impl<T> StructuralEq for Set<T>[src]

impl<T> StructuralPartialEq for Set<T>[src]

impl<T: Clone> ToOwned for Set<T>[src]

type Owned = SetBuf<T>

The resulting type after obtaining ownership.

Auto Trait Implementations

impl<T> RefUnwindSafe for Set<T> where
    T: RefUnwindSafe

impl<T> Send for Set<T> where
    T: Send

impl<T> Sync for Set<T> where
    T: Sync

impl<T> Unpin for Set<T> where
    T: Unpin

impl<T> UnwindSafe for Set<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.