Index: trunk/phase3/includes/Cdb_PHP.php |
— | — | @@ -17,7 +17,7 @@ |
18 | 18 | * $b must be less than 0x40000000 and greater than 0 |
19 | 19 | */ |
20 | 20 | public static function unsignedMod( $a, $b ) { |
21 | | - if ( $a < 0 ) { |
| 21 | + if ( $a & 0x80000000 ) { |
22 | 22 | $m = ( $a & 0x7fffffff ) % $b + 2 * ( 0x40000000 % $b ); |
23 | 23 | return $m % $b; |
24 | 24 | } else { |
— | — | @@ -32,7 +32,7 @@ |
33 | 33 | if ( $b == 0 ) { |
34 | 34 | return $a; |
35 | 35 | } |
36 | | - if ( $a < 0 ) { |
| 36 | + if ( $a & 0x80000000 ) { |
37 | 37 | return ( ( $a & 0x7fffffff ) >> $b ) | ( 0x40000000 >> ( $b - 1 ) ); |
38 | 38 | } else { |
39 | 39 | return $a >> $b; |
— | — | @@ -45,20 +45,21 @@ |
46 | 46 | public static function hash( $s ) { |
47 | 47 | $h = 5381; |
48 | 48 | for ( $i = 0; $i < strlen( $s ); $i++ ) { |
49 | | - $h5 = $h << 5; |
| 49 | + $h5 = ($h << 5) & 0xffffffff; |
50 | 50 | // Do a 32-bit sum |
51 | 51 | // Inlined here for speed |
52 | 52 | $sum = ($h & 0x3fffffff) + ($h5 & 0x3fffffff); |
53 | 53 | $h = |
54 | 54 | ( |
55 | 55 | ( $sum & 0x40000000 ? 1 : 0 ) |
56 | | - + ( $h < 0 ? 2 : 0 ) |
| 56 | + + ( $h & 0x80000000 ? 2 : 0 ) |
57 | 57 | + ( $h & 0x40000000 ? 1 : 0 ) |
58 | | - + ( $h5 < 0 ? 2 : 0 ) |
| 58 | + + ( $h5 & 0x80000000 ? 2 : 0 ) |
59 | 59 | + ( $h5 & 0x40000000 ? 1 : 0 ) |
60 | 60 | ) << 30 |
61 | 61 | | ( $sum & 0x3fffffff ); |
62 | 62 | $h ^= ord( $s[$i] ); |
| 63 | + $h &= 0xffffffff; |
63 | 64 | } |
64 | 65 | return $h; |
65 | 66 | } |