File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
iceberg-rust-spec/src/spec Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -1042,7 +1042,7 @@ fn sub_string(left: &str, right: &str) -> u64 {
10421042 . skip_while ( |( l, r) | l == r)
10431043 . try_fold ( 0 , |acc, ( l, r) | {
10441044 if let ( Some ( l) , Some ( r) ) = ( l. to_digit ( 36 ) , r. to_digit ( 36 ) ) {
1045- Some ( acc + ( l - r) . pow ( 2 ) )
1045+ Some ( acc + l . abs_diff ( r) . pow ( 2 ) )
10461046 } else {
10471047 None
10481048 }
@@ -1055,7 +1055,7 @@ fn sub_string(left: &str, right: &str) -> u64 {
10551055 let left = hasher. finish ( ) ;
10561056 hasher. write ( right. as_bytes ( ) ) ;
10571057 let right = hasher. finish ( ) ;
1058- left - right
1058+ left. abs_diff ( right)
10591059 }
10601060}
10611061
@@ -1555,4 +1555,16 @@ mod tests {
15551555 let result = value. transform ( & Transform :: Hour ) ;
15561556 assert ! ( matches!( result, Err ( Error :: NotSupported ( _) ) ) ) ;
15571557 }
1558+
1559+ #[ test]
1560+ fn test_sub_string ( ) {
1561+ assert_eq ! (
1562+ sub_string( "zyxwvutsrqponmlkjihgfedcba" , "abcdefghijklmnopqrstuvxyz" ) ,
1563+ 5354
1564+ ) ;
1565+ assert_eq ! (
1566+ sub_string( "abcdefghijklmnopqrstuvxyz" , "zyxwvutsrqponmlkjihgfedcba" ) ,
1567+ 5354
1568+ ) ;
1569+ }
15581570}
You can’t perform that action at this time.
0 commit comments