pub struct PagedBitSet<K, const PAGE: usize = DEFAULT_BIT_PAGE, D: Directory = Flat> { /* private fields */ }Expand description
A set of keys stored as bits at their slot indices.
PAGEis the number of 64-bit words per page. It must be non-zero.Dis the page directory:Flat(default),Radixfor wide keys, orTree.
The key’s DirectKey::Tag must be (). Use
PagedSparseSet for generational keys.
Set algebra and equality accept different directories with the same PAGE.
Implementations§
Source§impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory> PagedBitSet<K, PAGE, D>
impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory> PagedBitSet<K, PAGE, D>
Sourcepub const BITS_PER_PAGE: usize
pub const BITS_PER_PAGE: usize
The number of bits per page. The product must fit in usize.
Sourcepub fn allocated_pages(&self) -> usize
pub fn allocated_pages(&self) -> usize
Returns the number of allocated pages, including empty ones.
Sourcepub fn toggle(&mut self, key: K) -> bool
pub fn toggle(&mut self, key: K) -> bool
Flips the bit for key and returns whether it is now present.
Sourcepub fn insert_range(&mut self, keys: impl RangeBounds<K>) -> usize
pub fn insert_range(&mut self, keys: impl RangeBounds<K>) -> usize
Sets the bits in the range and returns the number of newly added keys.
The bounds refer to Key::index. Every slot in the range must
represent a valid key of type K. Unbounded endpoints refer to slot
zero and usize::MAX; use an explicit upper bound for narrow keys.
An empty or inverted range adds zero keys.
§Panics
Panics if the set would contain more than usize::MAX keys or the
directory cannot allocate a page.
use paged_collections::bit_set::PagedBitSet;
let mut set: PagedBitSet<u8, 1> = PagedBitSet::new();
assert_eq!(set.insert_range(63..=66), 4);
assert_eq!(set.insert_range(64..=66), 0);
assert_eq!(set.count_range(..=64), 2);
assert_eq!(set.remove_range(65..), 2);
assert_eq!(set.range(..).collect::<Vec<_>>(), [63, 64]);Sourcepub fn remove_range(&mut self, keys: impl RangeBounds<K>) -> usize
pub fn remove_range(&mut self, keys: impl RangeBounds<K>) -> usize
Clears the bits in the range and returns the number of removed keys.
The bounds refer to Key::index. An empty or inverted range removes
zero keys. Pages stay allocated.
Sourcepub fn count_range(&self, keys: impl RangeBounds<K>) -> usize
pub fn count_range(&self, keys: impl RangeBounds<K>) -> usize
Counts the set bits in the range.
The bounds refer to Key::index. An empty or inverted range has
count zero.
Sourcepub fn range(&self, keys: impl RangeBounds<K>) -> Range<'_, K, PAGE, D> ⓘ
pub fn range(&self, keys: impl RangeBounds<K>) -> Range<'_, K, PAGE, D> ⓘ
Iterates over the keys in the range in ascending slot-index order.
The bounds refer to Key::index. An empty or inverted range yields
no keys.
Sourcepub fn pop_first(&mut self) -> Option<K>
pub fn pop_first(&mut self) -> Option<K>
Removes and returns the key with the smallest slot index.
Sourcepub fn pop_last(&mut self) -> Option<K>
pub fn pop_last(&mut self) -> Option<K>
Removes and returns the key with the largest slot index.
Sourcepub fn next_occupant(&self, index: usize) -> Option<K>
pub fn next_occupant(&self, index: usize) -> Option<K>
Returns the first key at slot index or after it.
Sourcepub fn prev_occupant(&self, index: usize) -> Option<K>
pub fn prev_occupant(&self, index: usize) -> Option<K>
Returns the last key at slot index or before it.
Sourcepub fn retain(&mut self, keep: impl FnMut(K) -> bool)
pub fn retain(&mut self, keep: impl FnMut(K) -> bool)
Keeps keys for which keep returns true, visiting them in ascending
slot-index order.
If keep panics, the current key and those still to be visited stay
in the set.
Sourcepub fn drain(&mut self) -> Drain<'_, K, PAGE, D> ⓘ
pub fn drain(&mut self) -> Drain<'_, K, PAGE, D> ⓘ
Removes every key and returns them in ascending slot-index order.
Pages stay allocated, as with clear.
Keys are removed as the iterator yields them; dropping it removes the
rest. If it is leaked instead (mem::forget), the keys not yet
yielded stay in the set.
Sourcepub fn extract_if<F: FnMut(K) -> bool>(
&mut self,
pred: F,
) -> ExtractIf<'_, K, F, PAGE, D> ⓘ
pub fn extract_if<F: FnMut(K) -> bool>( &mut self, pred: F, ) -> ExtractIf<'_, K, F, PAGE, D> ⓘ
Removes the keys for which pred returns true and yields them,
visiting the keys in ascending slot-index order.
Keys are tested and removed as the iterator advances: those it has not
reached when it is dropped stay in the set. Use
retain if the removed keys are not needed.
use paged_collections::bit_set::PagedBitSet;
let mut set: PagedBitSet<u32> = (0..6).collect();
assert_eq!(set.extract_if(|k| k % 2 == 1).collect::<Vec<_>>(), [1, 3, 5]);
assert_eq!(set.drain().collect::<Vec<_>>(), [0, 2, 4]);
assert!(set.is_empty());Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Frees empty pages and shrinks the page directory.
Source§impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory> PagedBitSet<K, PAGE, D>
impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory> PagedBitSet<K, PAGE, D>
Sourcepub fn is_disjoint<D2: Directory>(
&self,
other: &PagedBitSet<K, PAGE, D2>,
) -> bool
pub fn is_disjoint<D2: Directory>( &self, other: &PagedBitSet<K, PAGE, D2>, ) -> bool
Returns whether the two sets have no key in common.
Sourcepub fn is_subset<D2: Directory>(&self, other: &PagedBitSet<K, PAGE, D2>) -> bool
pub fn is_subset<D2: Directory>(&self, other: &PagedBitSet<K, PAGE, D2>) -> bool
Returns whether every key in this set is also in other.
Sourcepub fn is_superset<D2: Directory>(
&self,
other: &PagedBitSet<K, PAGE, D2>,
) -> bool
pub fn is_superset<D2: Directory>( &self, other: &PagedBitSet<K, PAGE, D2>, ) -> bool
Returns whether every key in other is also in this set.
Sourcepub fn union<'a, D2: Directory>(
&'a self,
other: &'a PagedBitSet<K, PAGE, D2>,
) -> Union<'a, K, PAGE, D, D2> ⓘ
pub fn union<'a, D2: Directory>( &'a self, other: &'a PagedBitSet<K, PAGE, D2>, ) -> Union<'a, K, PAGE, D, D2> ⓘ
Iterates over keys in either set, in ascending slot-index order.
use paged_collections::bit_set::PagedBitSet;
use paged_collections::page::Tree;
let a: PagedBitSet<usize, 2> = [1, 5].into_iter().collect();
let b: PagedBitSet<usize, 2, Tree> = [2, 5].into_iter().collect();
assert_eq!(a.union(&b).collect::<Vec<_>>(), [1, 2, 5]);
assert_eq!((&a & &b).iter().collect::<Vec<_>>(), [5]);Sourcepub fn intersection<'a, D2: Directory>(
&'a self,
other: &'a PagedBitSet<K, PAGE, D2>,
) -> Intersection<'a, K, PAGE, D, D2> ⓘ
pub fn intersection<'a, D2: Directory>( &'a self, other: &'a PagedBitSet<K, PAGE, D2>, ) -> Intersection<'a, K, PAGE, D, D2> ⓘ
Iterates over keys in both sets, in ascending slot-index order.
Sourcepub fn difference<'a, D2: Directory>(
&'a self,
other: &'a PagedBitSet<K, PAGE, D2>,
) -> Difference<'a, K, PAGE, D, D2> ⓘ
pub fn difference<'a, D2: Directory>( &'a self, other: &'a PagedBitSet<K, PAGE, D2>, ) -> Difference<'a, K, PAGE, D, D2> ⓘ
Iterates over keys in this set that are absent from other, in
ascending slot-index order.
Sourcepub fn symmetric_difference<'a, D2: Directory>(
&'a self,
other: &'a PagedBitSet<K, PAGE, D2>,
) -> SymmetricDifference<'a, K, PAGE, D, D2> ⓘ
pub fn symmetric_difference<'a, D2: Directory>( &'a self, other: &'a PagedBitSet<K, PAGE, D2>, ) -> SymmetricDifference<'a, K, PAGE, D, D2> ⓘ
Iterates over keys in exactly one set, in ascending slot-index order.
Trait Implementations§
Source§impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory, D2: Directory> BitAnd<&PagedBitSet<K, PAGE, D2>> for &PagedBitSet<K, PAGE, D>
impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory, D2: Directory> BitAnd<&PagedBitSet<K, PAGE, D2>> for &PagedBitSet<K, PAGE, D>
Source§type Output = PagedBitSet<K, PAGE, D>
type Output = PagedBitSet<K, PAGE, D>
& operator.Source§impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory, D2: Directory> BitAndAssign<&PagedBitSet<K, PAGE, D2>> for PagedBitSet<K, PAGE, D>
impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory, D2: Directory> BitAndAssign<&PagedBitSet<K, PAGE, D2>> for PagedBitSet<K, PAGE, D>
Source§fn bitand_assign(&mut self, other: &PagedBitSet<K, PAGE, D2>)
fn bitand_assign(&mut self, other: &PagedBitSet<K, PAGE, D2>)
&= operation. Read moreSource§impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory, D2: Directory> BitOr<&PagedBitSet<K, PAGE, D2>> for &PagedBitSet<K, PAGE, D>
impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory, D2: Directory> BitOr<&PagedBitSet<K, PAGE, D2>> for &PagedBitSet<K, PAGE, D>
Source§type Output = PagedBitSet<K, PAGE, D>
type Output = PagedBitSet<K, PAGE, D>
| operator.Source§impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory, D2: Directory> BitOrAssign<&PagedBitSet<K, PAGE, D2>> for PagedBitSet<K, PAGE, D>
impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory, D2: Directory> BitOrAssign<&PagedBitSet<K, PAGE, D2>> for PagedBitSet<K, PAGE, D>
Source§fn bitor_assign(&mut self, other: &PagedBitSet<K, PAGE, D2>)
fn bitor_assign(&mut self, other: &PagedBitSet<K, PAGE, D2>)
|= operation. Read moreSource§impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory, D2: Directory> BitXor<&PagedBitSet<K, PAGE, D2>> for &PagedBitSet<K, PAGE, D>
impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory, D2: Directory> BitXor<&PagedBitSet<K, PAGE, D2>> for &PagedBitSet<K, PAGE, D>
Source§type Output = PagedBitSet<K, PAGE, D>
type Output = PagedBitSet<K, PAGE, D>
^ operator.Source§impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory, D2: Directory> BitXorAssign<&PagedBitSet<K, PAGE, D2>> for PagedBitSet<K, PAGE, D>
impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory, D2: Directory> BitXorAssign<&PagedBitSet<K, PAGE, D2>> for PagedBitSet<K, PAGE, D>
Source§fn bitxor_assign(&mut self, other: &PagedBitSet<K, PAGE, D2>)
fn bitxor_assign(&mut self, other: &PagedBitSet<K, PAGE, D2>)
^= operation. Read moreSource§impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory> Clone for PagedBitSet<K, PAGE, D>
impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory> Clone for PagedBitSet<K, PAGE, D>
Source§impl<K: DirectKey<Tag = ()> + Debug, const PAGE: usize, D: Directory> Debug for PagedBitSet<K, PAGE, D>
impl<K: DirectKey<Tag = ()> + Debug, const PAGE: usize, D: Directory> Debug for PagedBitSet<K, PAGE, D>
Source§impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory> Default for PagedBitSet<K, PAGE, D>
impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory> Default for PagedBitSet<K, PAGE, D>
Source§impl<'de, K: DirectKey<Tag = ()> + Deserialize<'de>, const PAGE: usize, D: Directory> Deserialize<'de> for PagedBitSet<K, PAGE, D>
Available on crate feature serde only.Deserializes from a sequence of keys, skipping duplicates.
impl<'de, K: DirectKey<Tag = ()> + Deserialize<'de>, const PAGE: usize, D: Directory> Deserialize<'de> for PagedBitSet<K, PAGE, D>
serde only.Deserializes from a sequence of keys, skipping duplicates.
Memory follows the key indices. With the Flat directory one large
index allocates a directory entry for every page below it. For
untrusted input, use Radix or
Tree, or validate the keys first.
Source§fn deserialize<De: Deserializer<'de>>(
deserializer: De,
) -> Result<Self, De::Error>
fn deserialize<De: Deserializer<'de>>( deserializer: De, ) -> Result<Self, De::Error>
impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory> Eq for PagedBitSet<K, PAGE, D>
Source§impl<'a, K: DirectKey<Tag = ()> + 'a, const PAGE: usize, D: Directory> Extend<&'a K> for PagedBitSet<K, PAGE, D>
impl<'a, K: DirectKey<Tag = ()> + 'a, const PAGE: usize, D: Directory> Extend<&'a K> for PagedBitSet<K, PAGE, D>
Source§fn extend<I: IntoIterator<Item = &'a K>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = &'a K>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: T)
fn extend_one(&mut self, item: T)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory> Extend<K> for PagedBitSet<K, PAGE, D>
impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory> Extend<K> for PagedBitSet<K, PAGE, D>
Source§fn extend<I: IntoIterator<Item = K>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = K>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: T)
fn extend_one(&mut self, item: T)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory> FromIterator<K> for PagedBitSet<K, PAGE, D>
impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory> FromIterator<K> for PagedBitSet<K, PAGE, D>
Source§fn from_iter<I: IntoIterator<Item = K>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = K>>(iter: I) -> Self
Source§impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory> Hash for PagedBitSet<K, PAGE, D>
Hashes the length and the nonzero words in ascending word-index order.
impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory> Hash for PagedBitSet<K, PAGE, D>
Hashes the length and the nonzero words in ascending word-index order.
Source§impl<'a, K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory> IntoIterator for &'a PagedBitSet<K, PAGE, D>
impl<'a, K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory> IntoIterator for &'a PagedBitSet<K, PAGE, D>
Source§impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory> IntoIterator for PagedBitSet<K, PAGE, D>
impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory> IntoIterator for PagedBitSet<K, PAGE, D>
Source§impl<'a, K: DirectKey<Tag = ()> + Send, const PAGE: usize, D: Directory> IntoParallelIterator for &'a PagedBitSet<K, PAGE, D>
Available on crate feature rayon only.
impl<'a, K: DirectKey<Tag = ()> + Send, const PAGE: usize, D: Directory> IntoParallelIterator for &'a PagedBitSet<K, PAGE, D>
rayon only.Source§impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory, D2: Directory> PartialEq<PagedBitSet<K, PAGE, D2>> for PagedBitSet<K, PAGE, D>
Compares the set bits, ignoring empty pages and the directory layout.
impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory, D2: Directory> PartialEq<PagedBitSet<K, PAGE, D2>> for PagedBitSet<K, PAGE, D>
Compares the set bits, ignoring empty pages and the directory layout.
Source§impl<K: DirectKey<Tag = ()> + Serialize, const PAGE: usize, D: Directory> Serialize for PagedBitSet<K, PAGE, D>
Available on crate feature serde only.Serializes as a sequence of keys in ascending slot-index order.
impl<K: DirectKey<Tag = ()> + Serialize, const PAGE: usize, D: Directory> Serialize for PagedBitSet<K, PAGE, D>
serde only.Serializes as a sequence of keys in ascending slot-index order.
Source§impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory, D2: Directory> Sub<&PagedBitSet<K, PAGE, D2>> for &PagedBitSet<K, PAGE, D>
impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory, D2: Directory> Sub<&PagedBitSet<K, PAGE, D2>> for &PagedBitSet<K, PAGE, D>
Source§type Output = PagedBitSet<K, PAGE, D>
type Output = PagedBitSet<K, PAGE, D>
- operator.Source§impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory, D2: Directory> SubAssign<&PagedBitSet<K, PAGE, D2>> for PagedBitSet<K, PAGE, D>
impl<K: DirectKey<Tag = ()>, const PAGE: usize, D: Directory, D2: Directory> SubAssign<&PagedBitSet<K, PAGE, D2>> for PagedBitSet<K, PAGE, D>
Source§fn sub_assign(&mut self, other: &PagedBitSet<K, PAGE, D2>)
fn sub_assign(&mut self, other: &PagedBitSet<K, PAGE, D2>)
-= operation. Read moreAuto Trait Implementations§
impl<K, const PAGE: usize, D> Forget for PagedBitSet<K, PAGE, D>
impl<K, const PAGE: usize, D> Freeze for PagedBitSet<K, PAGE, D>
impl<K, const PAGE: usize, D> Move for PagedBitSet<K, PAGE, D>
impl<K, const PAGE: usize, D> RefUnwindSafe for PagedBitSet<K, PAGE, D>
impl<K, const PAGE: usize, D> Send for PagedBitSet<K, PAGE, D>
impl<K, const PAGE: usize, D> Sync for PagedBitSet<K, PAGE, D>
impl<K, const PAGE: usize, D> Unpin for PagedBitSet<K, PAGE, D>
impl<K, const PAGE: usize, D> UnsafeUnpin for PagedBitSet<K, PAGE, D>
impl<K, const PAGE: usize, D> UnwindSafe for PagedBitSet<K, PAGE, D>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more