default_vec2

Struct BitSet

Source
pub struct BitSet<I = usize>(/* private fields */);
Expand description

A simple unbounded bitset that fits in 2 usizes worth of memory

It resizes its heap allocation whenever a number that wouldn’t otherwise fit in memory is added and doesn’t ever shrink its memory so it could end of wasting memory if a very large element is added and then removed

Implementations§

Source§

impl<I: Into<usize>> BitSet<I>

Source

pub fn insert(&mut self, x: I) -> bool

Adds an element 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.

use default_vec2::BitSet;
let mut s: BitSet<usize> = BitSet::default();
assert!(s.insert(0));
assert!(!s.insert(0));
Source

pub fn remove(&mut self, x: I) -> bool

Removes an element form the set Returns whether the value was present in the set.

use default_vec2::BitSet;
let mut s: BitSet<usize> = BitSet::default();
assert!(!s.remove(0));
s.insert(0);
assert!(s.remove(0));
assert!(!s.remove(0))
Source

pub fn contains(&self, x: I) -> bool

Checks if the set contains an element

Source

pub fn contains_mut(&mut self, x: I) -> bool

Same as contains but already reserves space for x

Source

pub fn clear(&mut self)

Removes all elements from the set

Source§

impl<I: From<usize> + Into<usize> + Copy> BitSet<I>

Source

pub fn iter(&self) -> impl Iterator<Item = I> + '_

Iterate over all elements in the set Run time is proportional to the largest element that has ever been in the set

Trait Implementations§

Source§

impl<'a, I> BitAndAssign<&'a BitSet> for BitSet<I>

Source§

fn bitand_assign(&mut self, rhs: &'a BitSet)

Sets *self to the intersection of self and other

§Example:
use default_vec2::BitSet;
let mut s1: BitSet<usize> = BitSet::from_iter([0, 1]);
let s2 = BitSet::from_iter([0, 42]);
s1 &= &s2;

assert_eq!(vec![0], s1.iter().collect::<Vec<_>>());
Source§

impl<'a, I> BitOrAssign<&'a BitSet> for BitSet<I>

Source§

fn bitor_assign(&mut self, rhs: &'a BitSet)

Sets *self to the intersection of self and other

§Example:
use default_vec2::BitSet;
let mut s1: BitSet<usize> = BitSet::from_iter([0, 1]);
let s2 = BitSet::from_iter([0, 42]);
s1 |= &s2;

assert_eq!(vec![0, 1, 42], s1.iter().collect::<Vec<_>>());
Source§

impl<'a, I> BitXorAssign<&'a BitSet> for BitSet<I>

Source§

fn bitxor_assign(&mut self, rhs: &'a BitSet)

Sets *self to the set symmetric difference of self and other

§Example:
use default_vec2::BitSet;
let mut s1: BitSet<usize> = BitSet::from_iter([0, 1]);
let s2 = BitSet::from_iter([0, 42]);
s1 ^= &s2;

assert_eq!(vec![1, 42], s1.iter().collect::<Vec<_>>());
Source§

impl<I> Clone for BitSet<I>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<I: From<usize> + Into<usize> + Copy + Debug> Debug for BitSet<I>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<I> Default for BitSet<I>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<I: Into<usize>> Extend<I> for BitSet<I>

Source§

fn extend<T: IntoIterator<Item = I>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<I: Into<usize>> FromIterator<I> for BitSet<I>

Source§

fn from_iter<T: IntoIterator<Item = I>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<'a, I> SubAssign<&'a BitSet> for BitSet<I>

Source§

fn sub_assign(&mut self, rhs: &'a BitSet)

Sets *self to the set difference of self and other

§Example:
use default_vec2::BitSet;
let mut s1: BitSet<usize> = BitSet::from_iter([0, 1]);
let s2 = BitSet::from_iter([0, 42]);
s1 -= &s2;

assert_eq!(vec![1], s1.iter().collect::<Vec<_>>());

Auto Trait Implementations§

§

impl<I> Freeze for BitSet<I>

§

impl<I> RefUnwindSafe for BitSet<I>
where I: RefUnwindSafe,

§

impl<I> Send for BitSet<I>
where I: Send,

§

impl<I> Sync for BitSet<I>
where I: Sync,

§

impl<I> Unpin for BitSet<I>
where I: Unpin,

§

impl<I> UnwindSafe for BitSet<I>
where I: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.