String hash code

This commit is contained in:
MaiaVictor 2021-11-08 04:09:16 -03:00
parent 1f8b3d8530
commit 5cdf4a052e
2 changed files with 17 additions and 1 deletions

View File

@ -0,0 +1,10 @@
// From https://stackoverflow.com/a/8831937/1031791
String.hash_code(str: String): U32
String.hash_code.go(str, 0)
String.hash_code.go(str: String, hash: U32): U32
case str {
nil: hash
cons: String.hash_code.go(str.tail, (U32.shl(hash, 5) - hash) + U16.to_u32(str.head))
}

View File

@ -1,2 +1,8 @@
Test: _
U32.murmur2(U32.murmur2(123))
Kindelia.hash_code("oi tudo bem? aaa", 0)
Kindelia.hash_code(str: String, hash: U32): U32
case str {
nil: hash
cons: Kindelia.hash_code(str.tail, (U32.shl(hash, 5) - hash) + U16.to_u32(str.head))
}