mirror of
https://github.com/Kindelia/Kind2.git
synced 2024-09-11 07:15:45 +03:00
String hash code
This commit is contained in:
parent
1f8b3d8530
commit
5cdf4a052e
10
base/String/hash_code.kind
Normal file
10
base/String/hash_code.kind
Normal 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))
|
||||
}
|
@ -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))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user