@@ -293,11 +293,14 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
293
293
///
294
294
/// Returns true if this changed the matrix, and false otherwise.
295
295
pub fn add ( & mut self , row : R , column : C ) -> bool {
296
- self . vector . resize_to_elem ( row, || SparseBitSet :: new ( ) ) ;
297
- if let None = self . vector . get ( row) {
298
- self . vector . push ( SparseBitSet :: new ( ) ) ;
299
- }
300
-
296
+ debug ! (
297
+ "add(row={:?}, column={:?}, current_len={})" ,
298
+ row,
299
+ column,
300
+ self . vector. len( )
301
+ ) ;
302
+ self . vector
303
+ . ensure_contains_elem ( row, || SparseBitSet :: new ( ) ) ;
301
304
self . vector [ row] . insert ( column)
302
305
}
303
306
@@ -321,7 +324,8 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
321
324
322
325
if read != write {
323
326
if self . vector . get ( read) . is_some ( ) {
324
- self . vector . resize_to_elem ( write, || SparseBitSet :: new ( ) ) ;
327
+ self . vector
328
+ . ensure_contains_elem ( write, || SparseBitSet :: new ( ) ) ;
325
329
let ( bit_set_read, bit_set_write) = self . vector . pick2_mut ( read, write) ;
326
330
327
331
for read_chunk in bit_set_read. chunks ( ) {
@@ -335,7 +339,8 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
335
339
336
340
/// Merge a row, `from`, into the `into` row.
337
341
pub fn merge_into ( & mut self , into : R , from : & SparseBitSet < C > ) -> bool {
338
- self . vector . resize_to_elem ( into, || SparseBitSet :: new ( ) ) ;
342
+ self . vector
343
+ . ensure_contains_elem ( into, || SparseBitSet :: new ( ) ) ;
339
344
self . vector [ into] . insert_from ( from)
340
345
}
341
346
0 commit comments