pub struct GrowSet { /* private fields */ }Expand description
A GrowSet is a set of integers that supports efficient addition and clearing.
It supports the following additional operations with the associated complexity:
- add - add an integer to the set in O(1) time
- clear - remove all members from the set in O(1) time
- pop - remove and return a random member of the set in O(1) time
GrowSets are useful for sets that need to be cleared frequently and rebuilt.
The implementation of GrowSet is based on “An Efficient Represtation of Sparse Sets”
by Briggs and Torczon (1993).
Implementations§
Source§impl<'a> GrowSet
impl<'a> GrowSet
Sourcepub fn with_capacity(size: usize) -> Self
pub fn with_capacity(size: usize) -> Self
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns one greater than the largest integer that can be stored in this set. That is, a set that can store integers from 0 to 5 will have a capacity of 6.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Return the number of integers in the set.
§Examples
use intset::GrowSet;
let mut set = GrowSet::with_capacity(5);
set.add(1);
set.add(4);
assert_eq!(set.len(), 2);Trait Implementations§
Auto Trait Implementations§
impl Freeze for GrowSet
impl RefUnwindSafe for GrowSet
impl Send for GrowSet
impl Sync for GrowSet
impl Unpin for GrowSet
impl UnwindSafe for GrowSet
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more