@@ -458,8 +458,8 @@ impl Buffer {
458458 F : Fn ( u64 ) -> u64 ,
459459 {
460460 // reserve capacity and set length so we can get a typed view of u64 chunks
461- let mut result =
462- MutableBuffer :: new ( crate :: util :: bit_util :: ceil ( len , 8 ) ) . with_bitset ( len / 64 * 8 , false ) ;
461+ let mut result = MutableBuffer :: new ( crate :: util :: bit_util :: ceil ( len , 8 ) )
462+ . with_bitset ( len / 64 * 8 , false ) ;
463463
464464 let left_chunks = self . bit_chunks ( offset, len) ;
465465
@@ -491,7 +491,14 @@ impl Buffer {
491491 /// * `other_offset` - The bit offset in other.
492492 /// * `len` - The number of bits to process.
493493 /// * `op` - The binary operation to apply.
494- pub fn bitwise_binary < F > ( & self , other : & Buffer , self_offset : usize , other_offset : usize , len : usize , op : F ) -> Buffer
494+ pub fn bitwise_binary < F > (
495+ & self ,
496+ other : & Buffer ,
497+ self_offset : usize ,
498+ other_offset : usize ,
499+ len : usize ,
500+ op : F ,
501+ ) -> Buffer
495502 where
496503 F : Fn ( u64 , u64 ) -> u64 ,
497504 {
@@ -1194,32 +1201,51 @@ mod tests {
11941201 let lengths = [ 1 , 2 , 7 , 8 , 9 , 15 , 16 ] ;
11951202
11961203 for & size in & buffer_sizes {
1197- for _ in 0 ..5 { // Generate 5 random pairs per size
1204+ for _ in 0 ..5 {
1205+ // Generate 5 random pairs per size
11981206 let left_vec: Vec < u8 > = ( 0 ..size) . map ( |_| rng. random :: < u8 > ( ) ) . collect ( ) ;
11991207 let right_vec: Vec < u8 > = ( 0 ..size) . map ( |_| rng. random :: < u8 > ( ) ) . collect ( ) ;
12001208 let left = Buffer :: from ( left_vec) ;
12011209 let right = Buffer :: from ( right_vec) ;
12021210 let buffer_bits = left. len ( ) * 8 ;
12031211
12041212 for & offset in & offsets {
1205- if offset >= buffer_bits { continue ; }
1213+ if offset >= buffer_bits {
1214+ continue ;
1215+ }
12061216 for & len in & lengths {
1207- if offset + len > buffer_bits { continue ; }
1217+ if offset + len > buffer_bits {
1218+ continue ;
1219+ }
12081220
12091221 // Test AND
1210- let new_and = left. bitwise_binary ( & right, offset, offset, len, |a, b| a & b) ;
1222+ let new_and =
1223+ left. bitwise_binary ( & right, offset, offset, len, |a, b| a & b) ;
12111224 let old_and = buffer_bin_and ( & left, offset, & right, offset, len) ;
1212- assert_eq ! ( new_and, old_and, "AND failed for offset={}, len={}" , offset, len) ;
1225+ assert_eq ! (
1226+ new_and, old_and,
1227+ "AND failed for offset={}, len={}" ,
1228+ offset, len
1229+ ) ;
12131230
12141231 // Test OR
12151232 let new_or = left. bitwise_binary ( & right, offset, offset, len, |a, b| a | b) ;
12161233 let old_or = buffer_bin_or ( & left, offset, & right, offset, len) ;
1217- assert_eq ! ( new_or, old_or, "OR failed for offset={}, len={}" , offset, len) ;
1234+ assert_eq ! (
1235+ new_or, old_or,
1236+ "OR failed for offset={}, len={}" ,
1237+ offset, len
1238+ ) ;
12181239
12191240 // Test XOR
1220- let new_xor = left. bitwise_binary ( & right, offset, offset, len, |a, b| a ^ b) ;
1241+ let new_xor =
1242+ left. bitwise_binary ( & right, offset, offset, len, |a, b| a ^ b) ;
12211243 let old_xor = buffer_bin_xor ( & left, offset, & right, offset, len) ;
1222- assert_eq ! ( new_xor, old_xor, "XOR failed for offset={}, len={}" , offset, len) ;
1244+ assert_eq ! (
1245+ new_xor, old_xor,
1246+ "XOR failed for offset={}, len={}" ,
1247+ offset, len
1248+ ) ;
12231249 }
12241250 }
12251251 }
@@ -1238,19 +1264,28 @@ mod tests {
12381264 let lengths = [ 1 , 2 , 7 , 8 , 9 , 15 , 16 ] ;
12391265
12401266 for & size in & buffer_sizes {
1241- for _ in 0 ..5 { // Generate 5 random buffers per size
1267+ for _ in 0 ..5 {
1268+ // Generate 5 random buffers per size
12421269 let vec: Vec < u8 > = ( 0 ..size) . map ( |_| rng. random :: < u8 > ( ) ) . collect ( ) ;
12431270 let buffer = Buffer :: from ( vec) ;
12441271 let buffer_bits = buffer. len ( ) * 8 ;
12451272
12461273 for & offset in & offsets {
1247- if offset >= buffer_bits { continue ; }
1274+ if offset >= buffer_bits {
1275+ continue ;
1276+ }
12481277 for & len in & lengths {
1249- if offset + len > buffer_bits { continue ; }
1278+ if offset + len > buffer_bits {
1279+ continue ;
1280+ }
12501281
12511282 let new_not = buffer. bitwise_unary ( offset, len, |a| !a) ;
12521283 let old_not = buffer_unary_not ( & buffer, offset, len) ;
1253- assert_eq ! ( new_not, old_not, "NOT failed for offset={}, len={}" , offset, len) ;
1284+ assert_eq ! (
1285+ new_not, old_not,
1286+ "NOT failed for offset={}, len={}" ,
1287+ offset, len
1288+ ) ;
12541289 }
12551290 }
12561291 }
@@ -1269,8 +1304,8 @@ mod tests {
12691304
12701305 // Boundary configurations for unary
12711306 let boundary_configs = vec ! [
1272- ( 0 , 0 ) , // zero length
1273- ( 0 , total_bits) , // full length
1307+ ( 0 , 0 ) , // zero length
1308+ ( 0 , total_bits) , // full length
12741309 ( 1 , total_bits - 1 ) , // offset 1, to end
12751310 ( 7 , total_bits - 7 ) , // offset 7, crosses byte
12761311 ( 8 , total_bits - 8 ) , // offset at byte boundary
@@ -1287,11 +1322,23 @@ mod tests {
12871322 // Test bitwise_unary
12881323 let result = buffer. bitwise_unary ( offset, len, |a| !a) ;
12891324 let expected_len = ( len + 7 ) / 8 ;
1290- assert_eq ! ( result. len( ) , expected_len, "Wrong length for offset={}, len={}" , offset, len) ;
1325+ assert_eq ! (
1326+ result. len( ) ,
1327+ expected_len,
1328+ "Wrong length for offset={}, len={}" ,
1329+ offset,
1330+ len
1331+ ) ;
12911332
12921333 // Idempotence: NOT twice should be identity, but since result is packed, compare lengths
12931334 let result_twice = Buffer :: from ( result. clone ( ) ) . bitwise_unary ( 0 , len, |a| !a) ;
1294- assert_eq ! ( result_twice. len( ) , expected_len, "NOT twice length mismatch for offset={}, len={}" , offset, len) ;
1335+ assert_eq ! (
1336+ result_twice. len( ) ,
1337+ expected_len,
1338+ "NOT twice length mismatch for offset={}, len={}" ,
1339+ offset,
1340+ len
1341+ ) ;
12951342 }
12961343 }
12971344
@@ -1311,8 +1358,8 @@ mod tests {
13111358
13121359 // Boundary configurations for binary
13131360 let boundary_configs = vec ! [
1314- ( 0 , 0 ) , // zero length
1315- ( 0 , total_bits) , // full length
1361+ ( 0 , 0 ) , // zero length
1362+ ( 0 , total_bits) , // full length
13161363 ( 1 , total_bits - 1 ) , // offset 1, to end
13171364 ( 7 , total_bits - 7 ) , // offset 7, crosses byte
13181365 ( 8 , total_bits - 8 ) , // offset at byte boundary
@@ -1329,35 +1376,54 @@ mod tests {
13291376 // Test bitwise_binary AND
13301377 let result_and = left. bitwise_binary ( & right, offset, offset, len, |a, b| a & b) ;
13311378 let expected_len = ( len + 7 ) / 8 ;
1332- assert_eq ! ( result_and. len( ) , expected_len, "AND wrong length for offset={}, len={}" , offset, len) ;
1379+ assert_eq ! (
1380+ result_and. len( ) ,
1381+ expected_len,
1382+ "AND wrong length for offset={}, len={}" ,
1383+ offset,
1384+ len
1385+ ) ;
13331386
13341387 // Compare with legacy for a few cases
1335- if len <= 64 { // to keep test fast
1388+ if len <= 64 {
1389+ // to keep test fast
13361390 let old_and = buffer_bin_and ( & left, offset, & right, offset, len) ;
1337- assert_eq ! ( result_and, old_and, "AND mismatch with legacy for offset={}, len={}" , offset, len) ;
1391+ assert_eq ! (
1392+ result_and, old_and,
1393+ "AND mismatch with legacy for offset={}, len={}" ,
1394+ offset, len
1395+ ) ;
13381396 }
13391397
13401398 // Test bitwise_binary OR
13411399 let result_or = left. bitwise_binary ( & right, offset, offset, len, |a, b| a | b) ;
1342- assert_eq ! ( result_or. len( ) , expected_len, "OR wrong length for offset={}, len={}" , offset, len) ;
1400+ assert_eq ! (
1401+ result_or. len( ) ,
1402+ expected_len,
1403+ "OR wrong length for offset={}, len={}" ,
1404+ offset,
1405+ len
1406+ ) ;
13431407
13441408 // Compare with legacy for a few cases
13451409 if len <= 64 {
13461410 let old_or = buffer_bin_or ( & left, offset, & right, offset, len) ;
1347- assert_eq ! ( result_or, old_or, "OR mismatch with legacy for offset={}, len={}" , offset, len) ;
1411+ assert_eq ! (
1412+ result_or, old_or,
1413+ "OR mismatch with legacy for offset={}, len={}" ,
1414+ offset, len
1415+ ) ;
13481416 }
13491417 }
13501418 }
13511419
1352-
1353-
13541420 #[ test]
13551421 fn test_buffer_bitwise_byte_boundary_regressions ( ) {
13561422 use crate :: buffer:: ops:: { buffer_bin_and, buffer_bin_or, buffer_unary_not} ;
13571423
13581424 // Construct small buffers
1359- let left = Buffer :: from ( vec ! [ 0b11110000u8 , 0b00001111u8 ] ) ; // 240, 15
1360- let right = Buffer :: from ( vec ! [ 0b10101010u8 , 0b01010101u8 ] ) ; // 170, 85
1425+ let left = Buffer :: from ( vec ! [ 0b11110000u8 , 0b00001111u8 ] ) ; // 240, 15
1426+ let right = Buffer :: from ( vec ! [ 0b10101010u8 , 0b01010101u8 ] ) ; // 170, 85
13611427
13621428 // (offset, len, description)
13631429 let cases: & [ ( usize , usize , & str ) ] = & [
0 commit comments