-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhashcode.monkey
More file actions
47 lines (36 loc) · 900 Bytes
/
hashcode.monkey
File metadata and controls
47 lines (36 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Strict
Public
' Imports:
Import config
Import types
' Functions:
' This is effectively just a rewrite of Java's 'hashCode' method:
Function HashCode:Int(S:String)
' Local variable(s):
Local Hash:Int = 0
' Compute the "hash code":
For Local I:= 0 Until S.Length
Hash = ((31*Hash) + S[I])
Next
' Return the resulting hash.
Return Hash
End
Function HashCode:Int(Data:Int[], Offset:Int, Length:Int)
' Local variable(s):
Local Hash:Int = 0
' Compute the "hash code":
For Local I:= Offset Until Length
Hash = ((31*Hash) + Data[I])
Next
' Return the resulting hash.
Return Hash
End
Function HashCode:Int(Data:Int[], Offset:Int=0)
Return HashCode(Data, Offset, Data.Length)
End
' This command simply wraps 'HashCode',
' and outputs the result in hexadecimal.
Function HashCodeInHex:HexValue(S:String)
' Return the hash-code in hexadecimal.
Return IntToHex(HashCode(S))
End