mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Rollup merge of #151148 - Jarcho:gbit_set, r=davidtwco
Add functions to `GrowableBitSet` Only really need `insert_range` for clippy, but may as well add the others. Using `Range` instead of `RangeBounds` since an end bound is needed for this to make sense and there aren't any traits to enforce that.
This commit is contained in:
@@ -1323,6 +1323,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 {
|
||||
@@ -1330,6 +1336,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()
|
||||
@@ -1341,6 +1357,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()
|
||||
|
||||
Reference in New Issue
Block a user