@@ -423,15 +423,6 @@ pub enum HybridBitSet<T: Idx> {
423423}
424424
425425impl < 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-
435426 pub fn new_empty ( domain_size : usize ) -> Self {
436427 HybridBitSet :: Sparse ( SparseBitSet :: new_empty ( domain_size) )
437428 }
@@ -487,20 +478,14 @@ impl<T: Idx> HybridBitSet<T> {
487478 // that doesn't matter because `elem` is already present.
488479 false
489480 }
490- HybridBitSet :: Sparse ( _ ) => {
481+ HybridBitSet :: Sparse ( sparse ) => {
491482 // 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
502488 }
503-
504489 HybridBitSet :: Dense ( dense) => dense. insert ( elem) ,
505490 }
506491 }
@@ -525,33 +510,26 @@ impl<T: Idx> HybridBitSet<T> {
525510
526511 pub fn union ( & mut self , other : & HybridBitSet < T > ) -> bool {
527512 match self {
528- HybridBitSet :: Sparse ( _ ) => {
513+ HybridBitSet :: Sparse ( self_sparse ) => {
529514 match other {
530515 HybridBitSet :: Sparse ( other_sparse) => {
531516 // 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.
534519 assert_eq ! ( self . domain_size( ) , other. domain_size( ) ) ;
535- let mut self_hybrid = mem:: replace ( self , HybridBitSet :: dummy ( ) ) ;
536520 let mut changed = false ;
537521 for elem in other_sparse. iter ( ) {
538- changed |= self_hybrid . insert ( * elem) ;
522+ changed |= self . insert ( * elem) ;
539523 }
540- * self = self_hybrid;
541524 changed
542525 }
543526 HybridBitSet :: Dense ( other_dense) => {
544527 // `self` is sparse and `other` is dense. Densify
545528 // `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
555533 }
556534 }
557535 }
0 commit comments