@@ -453,6 +453,11 @@ impl<T: Idx> ChunkedBitSet<T> {
453
453
ChunkedBitSet :: new ( domain_size, /* is_empty */ false )
454
454
}
455
455
456
+ pub fn clear ( & mut self ) {
457
+ let domain_size = self . domain_size ( ) ;
458
+ * self = ChunkedBitSet :: new_empty ( domain_size) ;
459
+ }
460
+
456
461
#[ cfg( test) ]
457
462
fn chunks ( & self ) -> & [ Chunk ] {
458
463
& self . chunks
@@ -1885,7 +1890,7 @@ impl<R: Idx, C: Idx> fmt::Debug for BitMatrix<R, C> {
1885
1890
/// sparse representation.
1886
1891
///
1887
1892
/// 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 >)`.
1889
1894
/// Furthermore, any previously uninstantiated rows prior to it will be
1890
1895
/// instantiated as `None`. Those prior rows may themselves become fully
1891
1896
/// instantiated later on if any of their bits are set.
@@ -1899,7 +1904,7 @@ where
1899
1904
C : Idx ,
1900
1905
{
1901
1906
num_columns : usize ,
1902
- rows : IndexVec < R , Option < HybridBitSet < C > > > ,
1907
+ rows : IndexVec < R , Option < ChunkedBitSet < C > > > ,
1903
1908
}
1904
1909
1905
1910
impl < R : Idx , C : Idx > SparseBitMatrix < R , C > {
@@ -1908,10 +1913,10 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
1908
1913
Self { num_columns, rows : IndexVec :: new ( ) }
1909
1914
}
1910
1915
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 ) )
1915
1920
}
1916
1921
1917
1922
/// Sets the cell at `(row, column)` to true. Put another way, insert
@@ -1985,17 +1990,17 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
1985
1990
self . row ( row) . into_iter ( ) . flat_map ( |r| r. iter ( ) )
1986
1991
}
1987
1992
1988
- pub fn row ( & self , row : R ) -> Option < & HybridBitSet < C > > {
1993
+ pub fn row ( & self , row : R ) -> Option < & ChunkedBitSet < C > > {
1989
1994
self . rows . get ( row) ?. as_ref ( )
1990
1995
}
1991
1996
1992
1997
/// 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.
1994
1999
///
1995
2000
/// Returns true if the row was changed.
1996
2001
pub fn intersect_row < Set > ( & mut self , row : R , set : & Set ) -> bool
1997
2002
where
1998
- HybridBitSet < C > : BitRelations < Set > ,
2003
+ ChunkedBitSet < C > : BitRelations < Set > ,
1999
2004
{
2000
2005
match self . rows . get_mut ( row) {
2001
2006
Some ( Some ( row) ) => row. intersect ( set) ,
@@ -2004,12 +2009,12 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
2004
2009
}
2005
2010
2006
2011
/// 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.
2008
2013
///
2009
2014
/// Returns true if the row was changed.
2010
2015
pub fn subtract_row < Set > ( & mut self , row : R , set : & Set ) -> bool
2011
2016
where
2012
- HybridBitSet < C > : BitRelations < Set > ,
2017
+ ChunkedBitSet < C > : BitRelations < Set > ,
2013
2018
{
2014
2019
match self . rows . get_mut ( row) {
2015
2020
Some ( Some ( row) ) => row. subtract ( set) ,
@@ -2018,12 +2023,12 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
2018
2023
}
2019
2024
2020
2025
/// Unions `row` with `set`. `set` can be either `BitSet` or
2021
- /// `HybridBitSet `.
2026
+ /// `ChunkedBitSet `.
2022
2027
///
2023
2028
/// Returns true if the row was changed.
2024
2029
pub fn union_row < Set > ( & mut self , row : R , set : & Set ) -> bool
2025
2030
where
2026
- HybridBitSet < C > : BitRelations < Set > ,
2031
+ ChunkedBitSet < C > : BitRelations < Set > ,
2027
2032
{
2028
2033
self . ensure_row ( row) . union ( set)
2029
2034
}
0 commit comments