File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -968,7 +968,7 @@ impl FixedBitSet {
968968 . iter ( )
969969 . zip ( other. as_slice ( ) . iter ( ) )
970970 . map ( |( x, y) | ( * x & !* y) ) ,
971- )
971+ ) + Self :: batch_count_ones ( self . as_slice ( ) . iter ( ) . skip ( other . as_slice ( ) . len ( ) ) . copied ( ) )
972972 }
973973
974974 /// Computes how many bits would be set in the symmetric difference between two bitsets.
Original file line number Diff line number Diff line change @@ -765,6 +765,45 @@ fn difference() {
765765 count, iterator_count,
766766 "intersection and intersection_count produce the same results"
767767 ) ;
768+
769+ let a_len = 151 ;
770+ let b_len = 83 ;
771+ let a_start = 0 ;
772+ let a_end = 134 ;
773+ let b_start = 53 ;
774+ let mut a = FixedBitSet :: with_capacity ( a_len) ;
775+ let mut b = FixedBitSet :: with_capacity ( b_len) ;
776+ a. set_range ( a_start..a_end, true ) ;
777+ b. set_range ( b_start..b_len, true ) ;
778+ let count = a. difference_count ( & b) ;
779+ let iterator_count = a. difference ( & b) . count ( ) ;
780+ let mut a_diff_b = a. difference ( & b) . collect :: < FixedBitSet > ( ) ;
781+ for i in a_start..b_start {
782+ assert ! ( a_diff_b. contains( i) ) ;
783+ }
784+ for i in b_start..b_len {
785+ assert ! ( !a_diff_b. contains( i) ) ;
786+ }
787+ for i in b_len..a_end {
788+ assert ! ( a_diff_b. contains( i) ) ;
789+ }
790+
791+ a. difference_with ( & b) ;
792+ // difference + collect produces the same results but with a shorter length.
793+ a_diff_b. grow ( a. len ( ) ) ;
794+ assert_eq ! (
795+ a_diff_b, a,
796+ "difference and difference_with produce the same results"
797+ ) ;
798+ assert_eq ! (
799+ a_diff_b. count_ones( ..) ,
800+ count,
801+ "difference and difference_count produce the same results"
802+ ) ;
803+ assert_eq ! (
804+ count, iterator_count,
805+ "intersection and intersection_count produce the same results"
806+ ) ;
768807}
769808
770809#[ test]
You can’t perform that action at this time.
0 commit comments