Add functions to GrowableBitSet.

This commit is contained in:
Jason Newcomb
2026-01-14 19:03:30 -05:00
parent 86a49fd71f
commit e7d56c6d01
+24
View File
@@ -1336,6 +1336,12 @@ pub fn insert(&mut self, elem: T) -> bool {
self.bit_set.insert(elem)
}
#[inline]
pub fn insert_range(&mut self, elems: Range<T>) {
self.ensure(elems.end.index());
self.bit_set.insert_range(elems);
}
/// Returns `true` if the set has changed.
#[inline]
pub fn remove(&mut self, elem: T) -> bool {
@@ -1343,6 +1349,16 @@ pub fn remove(&mut self, elem: T) -> bool {
self.bit_set.remove(elem)
}
#[inline]
pub fn clear(&mut self) {
self.bit_set.clear();
}
#[inline]
pub fn count(&self) -> usize {
self.bit_set.count()
}
#[inline]
pub fn is_empty(&self) -> bool {
self.bit_set.is_empty()
@@ -1354,6 +1370,14 @@ pub fn contains(&self, elem: T) -> bool {
self.bit_set.words.get(word_index).is_some_and(|word| (word & mask) != 0)
}
#[inline]
pub fn contains_any(&self, elems: Range<T>) -> bool {
elems.start.index() < self.bit_set.domain_size
&& self
.bit_set
.contains_any(elems.start..T::new(elems.end.index().min(self.bit_set.domain_size)))
}
#[inline]
pub fn iter(&self) -> BitIter<'_, T> {
self.bit_set.iter()