Skip to content

Commit e787d35

Browse files
committed
Stop using HybridBitSet in SparseBitMatrix.
Use `ChunkedBitSet` instead.
1 parent af540b8 commit e787d35

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

compiler/rustc_index/src/bit_set.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,11 @@ impl<T: Idx> ChunkedBitSet<T> {
453453
ChunkedBitSet::new(domain_size, /* is_empty */ false)
454454
}
455455

456+
pub fn clear(&mut self) {
457+
let domain_size = self.domain_size();
458+
*self = ChunkedBitSet::new_empty(domain_size);
459+
}
460+
456461
#[cfg(test)]
457462
fn chunks(&self) -> &[Chunk] {
458463
&self.chunks
@@ -1885,7 +1890,7 @@ impl<R: Idx, C: Idx> fmt::Debug for BitMatrix<R, C> {
18851890
/// sparse representation.
18861891
///
18871892
/// Initially, every row has no explicit representation. If any bit within a
1888-
/// row is set, the entire row is instantiated as `Some(<HybridBitSet>)`.
1893+
/// row is set, the entire row is instantiated as `Some(<ChunkedBitSet>)`.
18891894
/// Furthermore, any previously uninstantiated rows prior to it will be
18901895
/// instantiated as `None`. Those prior rows may themselves become fully
18911896
/// instantiated later on if any of their bits are set.
@@ -1899,7 +1904,7 @@ where
18991904
C: Idx,
19001905
{
19011906
num_columns: usize,
1902-
rows: IndexVec<R, Option<HybridBitSet<C>>>,
1907+
rows: IndexVec<R, Option<ChunkedBitSet<C>>>,
19031908
}
19041909

19051910
impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
@@ -1908,10 +1913,10 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
19081913
Self { num_columns, rows: IndexVec::new() }
19091914
}
19101915

1911-
fn ensure_row(&mut self, row: R) -> &mut HybridBitSet<C> {
1912-
// Instantiate any missing rows up to and including row `row` with an empty HybridBitSet.
1913-
// Then replace row `row` with a full HybridBitSet if necessary.
1914-
self.rows.get_or_insert_with(row, || HybridBitSet::new_empty(self.num_columns))
1916+
fn ensure_row(&mut self, row: R) -> &mut ChunkedBitSet<C> {
1917+
// Instantiate any missing rows up to and including row `row` with an empty ChunkedBitSet.
1918+
// Then replace row `row` with a full ChunkedBitSet if necessary.
1919+
self.rows.get_or_insert_with(row, || ChunkedBitSet::new_empty(self.num_columns))
19151920
}
19161921

19171922
/// Sets the cell at `(row, column)` to true. Put another way, insert
@@ -1985,17 +1990,17 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
19851990
self.row(row).into_iter().flat_map(|r| r.iter())
19861991
}
19871992

1988-
pub fn row(&self, row: R) -> Option<&HybridBitSet<C>> {
1993+
pub fn row(&self, row: R) -> Option<&ChunkedBitSet<C>> {
19891994
self.rows.get(row)?.as_ref()
19901995
}
19911996

19921997
/// Intersects `row` with `set`. `set` can be either `BitSet` or
1993-
/// `HybridBitSet`. Has no effect if `row` does not exist.
1998+
/// `ChunkedBitSet`. Has no effect if `row` does not exist.
19941999
///
19952000
/// Returns true if the row was changed.
19962001
pub fn intersect_row<Set>(&mut self, row: R, set: &Set) -> bool
19972002
where
1998-
HybridBitSet<C>: BitRelations<Set>,
2003+
ChunkedBitSet<C>: BitRelations<Set>,
19992004
{
20002005
match self.rows.get_mut(row) {
20012006
Some(Some(row)) => row.intersect(set),
@@ -2004,12 +2009,12 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
20042009
}
20052010

20062011
/// Subtracts `set` from `row`. `set` can be either `BitSet` or
2007-
/// `HybridBitSet`. Has no effect if `row` does not exist.
2012+
/// `ChunkedBitSet`. Has no effect if `row` does not exist.
20082013
///
20092014
/// Returns true if the row was changed.
20102015
pub fn subtract_row<Set>(&mut self, row: R, set: &Set) -> bool
20112016
where
2012-
HybridBitSet<C>: BitRelations<Set>,
2017+
ChunkedBitSet<C>: BitRelations<Set>,
20132018
{
20142019
match self.rows.get_mut(row) {
20152020
Some(Some(row)) => row.subtract(set),
@@ -2018,12 +2023,12 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
20182023
}
20192024

20202025
/// Unions `row` with `set`. `set` can be either `BitSet` or
2021-
/// `HybridBitSet`.
2026+
/// `ChunkedBitSet`.
20222027
///
20232028
/// Returns true if the row was changed.
20242029
pub fn union_row<Set>(&mut self, row: R, set: &Set) -> bool
20252030
where
2026-
HybridBitSet<C>: BitRelations<Set>,
2031+
ChunkedBitSet<C>: BitRelations<Set>,
20272032
{
20282033
self.ensure_row(row).union(set)
20292034
}

0 commit comments

Comments
 (0)