Skip to content

Commit

Permalink
use normal name convention since we have const now
Browse files Browse the repository at this point in the history
  • Loading branch information
bobzhang committed Feb 8, 2025
1 parent 3370468 commit 5250e68
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions builtin/hasher.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
// limitations under the License.

///|
let gPRIME1 = 0x9E3779B1

This comment has been minimized.

Copy link
@hackwaly

hackwaly Feb 8, 2025

Contributor

I think the prefix g is workaround while it must be lowercase before we have const support.

const GPRIME1 = 0x9E3779B1

///|
let gPRIME2 = 0x85EBCA77
const GPRIMES2 = 0x85EBCA77

///|
let gPRIME3 = 0xC2B2AE3D
const GPRIME3 = 0xC2B2AE3D

///|
let gPRIME4 = 0x27D4EB2F
const GPRIME4 = 0x27D4EB2F

///|
let gPRIME5 = 0x165667B1
const GPRIME5 = 0x165667B1

///|
/// Represents a hasher that implements the xxHash32 algorithm. The hasher
Expand Down Expand Up @@ -73,7 +73,7 @@ struct Hasher {
/// }
/// ```
pub fn Hasher::new(seed~ : Int = 0) -> Hasher {
{ acc: seed + gPRIME5 }
{ acc: seed + GPRIME5 }
}

///|
Expand Down Expand Up @@ -417,21 +417,21 @@ pub fn Hasher::finalize(self : Hasher) -> Int {
fn Hasher::avalanche(self : Hasher) -> Int {
let mut acc = self.acc.reinterpret_as_uint()
acc = acc ^ (acc >> 15)
acc *= gPRIME2.reinterpret_as_uint()
acc *= GPRIMES2.reinterpret_as_uint()
acc = acc ^ (acc >> 13)
acc *= gPRIME3.reinterpret_as_uint()
acc *= GPRIME3.reinterpret_as_uint()
acc = acc ^ (acc >> 16)
acc.reinterpret_as_int()
}

///|
fn Hasher::consume4(self : Hasher, input : Int) -> Unit {
self.acc = rotl(self.acc + input * gPRIME3, 17) * gPRIME4
self.acc = rotl(self.acc + input * GPRIME3, 17) * GPRIME4
}

///|
fn Hasher::consume1(self : Hasher, input : Byte) -> Unit {
self.acc = rotl(self.acc + input.to_int() * gPRIME5, 11) * gPRIME1
self.acc = rotl(self.acc + input.to_int() * GPRIME5, 11) * GPRIME1
}

///|
Expand Down

0 comments on commit 5250e68

Please sign in to comment.