@@ -423,15 +423,6 @@ pub enum HybridBitSet<T: Idx> {
423
423
}
424
424
425
425
impl < T : Idx > HybridBitSet < T > {
426
- // FIXME: This function is used in conjunction with `mem::replace()` in
427
- // several pieces of awful code below. I can't work out how else to appease
428
- // the borrow checker.
429
- fn dummy ( ) -> Self {
430
- // The cheapest HybridBitSet to construct, which is only used to get
431
- // around the borrow checker.
432
- HybridBitSet :: Sparse ( SparseBitSet :: new_empty ( 0 ) )
433
- }
434
-
435
426
pub fn new_empty ( domain_size : usize ) -> Self {
436
427
HybridBitSet :: Sparse ( SparseBitSet :: new_empty ( domain_size) )
437
428
}
@@ -487,20 +478,14 @@ impl<T: Idx> HybridBitSet<T> {
487
478
// that doesn't matter because `elem` is already present.
488
479
false
489
480
}
490
- HybridBitSet :: Sparse ( _ ) => {
481
+ HybridBitSet :: Sparse ( sparse ) => {
491
482
// The set is sparse and full. Convert to a dense set.
492
- match mem:: replace ( self , HybridBitSet :: dummy ( ) ) {
493
- HybridBitSet :: Sparse ( sparse) => {
494
- let mut dense = sparse. to_dense ( ) ;
495
- let changed = dense. insert ( elem) ;
496
- assert ! ( changed) ;
497
- * self = HybridBitSet :: Dense ( dense) ;
498
- changed
499
- }
500
- _ => unreachable ! ( )
501
- }
483
+ let mut dense = sparse. to_dense ( ) ;
484
+ let changed = dense. insert ( elem) ;
485
+ assert ! ( changed) ;
486
+ * self = HybridBitSet :: Dense ( dense) ;
487
+ changed
502
488
}
503
-
504
489
HybridBitSet :: Dense ( dense) => dense. insert ( elem) ,
505
490
}
506
491
}
@@ -525,33 +510,26 @@ impl<T: Idx> HybridBitSet<T> {
525
510
526
511
pub fn union ( & mut self , other : & HybridBitSet < T > ) -> bool {
527
512
match self {
528
- HybridBitSet :: Sparse ( _ ) => {
513
+ HybridBitSet :: Sparse ( self_sparse ) => {
529
514
match other {
530
515
HybridBitSet :: Sparse ( other_sparse) => {
531
516
// Both sets are sparse. Add the elements in
532
- // `other_sparse` to `self_hybrid ` one at a time. This
533
- // may or may not cause `self_hybrid ` to be densified.
517
+ // `other_sparse` to `self ` one at a time. This
518
+ // may or may not cause `self ` to be densified.
534
519
assert_eq ! ( self . domain_size( ) , other. domain_size( ) ) ;
535
- let mut self_hybrid = mem:: replace ( self , HybridBitSet :: dummy ( ) ) ;
536
520
let mut changed = false ;
537
521
for elem in other_sparse. iter ( ) {
538
- changed |= self_hybrid . insert ( * elem) ;
522
+ changed |= self . insert ( * elem) ;
539
523
}
540
- * self = self_hybrid;
541
524
changed
542
525
}
543
526
HybridBitSet :: Dense ( other_dense) => {
544
527
// `self` is sparse and `other` is dense. Densify
545
528
// `self` and then do the bitwise union.
546
- match mem:: replace ( self , HybridBitSet :: dummy ( ) ) {
547
- HybridBitSet :: Sparse ( self_sparse) => {
548
- let mut new_dense = self_sparse. to_dense ( ) ;
549
- let changed = new_dense. union ( other_dense) ;
550
- * self = HybridBitSet :: Dense ( new_dense) ;
551
- changed
552
- }
553
- _ => unreachable ! ( )
554
- }
529
+ let mut new_dense = self_sparse. to_dense ( ) ;
530
+ let changed = new_dense. union ( other_dense) ;
531
+ * self = HybridBitSet :: Dense ( new_dense) ;
532
+ changed
555
533
}
556
534
}
557
535
}
0 commit comments