[−][src]Struct tinyset::set64::Set64
A set type that can store any type that fits in a u64
. This set
type is very space-efficient in storing small or closely spaced
integers, while not being bad at storing large integers.
Major caveat The Set64
type defines iterators (drain()
and
iter()
) that iterate over T
rather than &T
. This is a break
with standard libray convention, and can be annoying if you are
translating code from HashSet
to Set64
. The motivation for
this is several-fold:
-
Set64
does not storeT
directly in its data structures (which would waste space), so there is no reference to the data to take. This does not make it impossible, but does mean we would have to fabricate aT
and return a reference to it, which is awkward and ugly. -
There is no inefficiency involved in returning
T
, since it is necessarily no larger than a pointer.
Examples
use tinyset::Set64; let a: Set64<char> = "Hello world".chars().collect(); for x in "Hello world".chars() { assert!(a.contains(&x)); } for x in a { assert!("Hello world".contains(x)); }
Storage details
Internally a Set64
is identical to a [SetU64], so read there for
details. In short, small sets are the size of a pointer with no
heap storage. Densely packed sets are around a bit per member.
Intermediate sets have intermediate storage. The worst case
scenario is large integers widely spaced apart, in which case the
storage is similar to a std::collections::HashSet
.
Implementations
impl<T: Fits64> Set64<T>
[src]
impl<T: Fits64> Set64<T>
[src]
pub fn new() -> Self
[src]
Creates an empty set..
pub fn with_capacity(_cap: usize) -> Self
[src]
Creates an empty set with the specified capacity.
pub fn insert(&mut self, elem: T) -> bool
[src]
Adds a value to the set.
If the set did not have this value present, true
is returned.
If the set did have this value present, false
is returned.
pub fn len(&self) -> usize
[src]
Returns the number of elements in the set.
pub fn contains<R: Borrow<T>>(&self, value: R) -> bool
[src]
Returns true if the set contains a value.
pub fn remove(&mut self, value: &T) -> bool
[src]
Removes an element, and returns true if that element was present.
pub fn iter<'a>(&'a self) -> impl Iterator<Item = T> + 'a
[src]
Iterate
pub fn drain<'a>(&'a mut self) -> impl Iterator<Item = T> + 'a
[src]
Drain
Trait Implementations
impl<'a, 'b, T: Fits64> BitOr<&'b Set64<T>> for &'a Set64<T>
[src]
type Output = Set64<T>
The resulting type after applying the |
operator.
fn bitor(self, rhs: &Set64<T>) -> Set64<T>
[src]
Returns the union of self
and rhs
as a new Set64<T>
.
Examples
use tinyset::Set64; let a: Set64<u32> = vec![1, 2, 3].into_iter().collect(); let b: Set64<u32> = vec![3, 4, 5].into_iter().collect(); let set = &a | &b; let mut i = 0; let expected = [1, 2, 3, 4, 5]; for x in set { assert!(expected.contains(&x)); i += 1; } assert_eq!(i, expected.len());
impl<T: Clone + Fits64> Clone for Set64<T>
[src]
impl<T: Debug + Fits64> Debug for Set64<T>
[src]
impl<T: Fits64> Default for Set64<T>
[src]
impl<T: Fits64> Eq for Set64<T>
[src]
impl<T: Fits64> Extend<T> for Set64<T>
[src]
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
[src]
Adds a bunch of elements to the set
Examples
use tinyset::Set64; let mut a: Set64<u32> = vec![1, 2, 3].into_iter().collect(); a.extend(vec![3, 4, 5]); let mut i = 0; let expected = [1, 2, 3, 4, 5]; for x in a { assert!(expected.contains(&x)); i += 1; } assert_eq!(i, expected.len());
fn extend_one(&mut self, item: A)
[src]
fn extend_reserve(&mut self, additional: usize)
[src]
impl<T: Fits64> FromIterator<T> for Set64<T>
[src]
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
[src]
impl<T: Fits64> Hash for Set64<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: Fits64> IntoIterator for Set64<T>
[src]
type Item = T
The type of the elements being iterated over.
type IntoIter = IntoIter<T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> IntoIter<T>
[src]
impl<T: Fits64> PartialEq<Set64<T>> for Set64<T>
[src]
impl<'a, 'b, T: Fits64> Sub<&'b Set64<T>> for &'a Set64<T>
[src]
type Output = Set64<T>
The resulting type after applying the -
operator.
fn sub(self, rhs: &Set64<T>) -> Set64<T>
[src]
Returns the difference of self
and rhs
as a new Set64<T>
.
Examples
use tinyset::Set64; let a: Set64<u32> = vec![1, 2, 3].into_iter().collect(); let b: Set64<u32> = vec![3, 4, 5].into_iter().collect(); let set = &a - &b; let mut i = 0; let expected = [1, 2]; for x in set { assert!(expected.contains(&x)); i += 1; } assert_eq!(i, expected.len());
Auto Trait Implementations
impl<T> RefUnwindSafe for Set64<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Set64<T> where
T: Send,
T: Send,
impl<T> Sync for Set64<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Set64<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Set64<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
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> 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 = Infallible
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<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,