@@ -407,10 +407,10 @@ macro_rules! uint_module {
407407 assert_eq!( & xs, & [ 0xff , 0x00 , 0x0f , 0xf0 , 0x33 , 0xcc , 0x55 , 0xaa ] ) ;
408408 }
409409
410- // `256 * BITS` masks
410+ // `256 * ( BITS / 5) ` masks
411411 let sparse_masks = ( i8 :: MIN ..=i8 :: MAX )
412412 . map( |i| ( i as i128 as $T) . rotate_right( 4 ) )
413- . flat_map( |x| ( 0 ..$T:: BITS ) . map( move |s| ( ( 1 as $T ) << s ) ^ x ) ) ;
413+ . flat_map( |x| ( 0 ..$T:: BITS ) . step_by ( 5 ) . map( move |r| x . rotate_right ( r ) ) ) ;
414414
415415 for sparse in sparse_masks {
416416 // Collect the set bits to sequential low bits
@@ -419,21 +419,19 @@ macro_rules! uint_module {
419419 assert_eq!( count, dense. count_ones( ) ) ;
420420 assert_eq!( count, dense. trailing_ones( ) ) ;
421421
422+ // Check that each bit is individually mapped correctly
422423 let mut t = sparse;
423- for k in 0 ..$T:: BITS {
424- let x = ( ( 1 as $T) << k) . scatter_bits( sparse) ;
425- let y = t. isolate_lowest_one( ) ;
426- assert_eq!( x, y) ;
427- t ^= y;
428- }
429-
430- let mut t = sparse;
431- for k in 0 ..count {
432- let y = t. isolate_lowest_one( ) ;
433- let x = y. gather_bits( sparse) ;
434- assert_eq!( x, ( 1 as $T) << k) ;
435- t ^= y;
424+ let mut bit = 1 as $T;
425+ for _ in 0 ..count {
426+ let lowest_one = t. isolate_lowest_one( ) ;
427+ assert_eq!( lowest_one, bit. scatter_bits( sparse) ) ;
428+ assert_eq!( bit, lowest_one. gather_bits( sparse) ) ;
429+ t ^= lowest_one;
430+ bit <<= 1 ;
436431 }
432+ // Other bits are ignored
433+ assert_eq!( 0 , bit. wrapping_neg( ) . scatter_bits( sparse) ) ;
434+ assert_eq!( 0 , ( !sparse) . gather_bits( sparse) ) ;
437435
438436 for & x in & xs {
439437 // Gather bits from `x & sparse` to `dense`
0 commit comments