forked from Krowemoh/TCL-Utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MAP.HAS
50 lines (50 loc) · 796 Bytes
/
MAP.HAS
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
48
49
50
SUBROUTINE MAP.GET(MAT MAP,SIZE,KEY,FLAG)
*
GIT.FILENAME = 'MAP.HAS'
GIT.REPO = 'https://github.com/Krowemoh/TCL-Utilities.git'
*
* VERSION
*
VERSION = '1'
*
EQU TRUE TO 1
EQU FALSE TO 0
*
@USER1 = 'MAP.HAS'
@USER2 = 'MAP.HAS'
*
KEY.LEN = LEN(KEY)
*
HASH = 5381
*
FOR I = 1 TO KEY.LEN
C = KEY[I,1]
*
* HASH = HASH * 33 + C
*
HASH = SADD(SMUL(HASH,33),SEQ(C))
NEXT I
*
* POS = HASH - (INT(HASH / SIZE) * HASH)
*
D = SDIV(HASH,SIZE)
E = INDEX(D,'.',1)
*
IF E = 0 THEN E = LEN(D)
*
DIVISION = D[1,E]
MULTIPLE = SMUL(DIVISION,SIZE)
POS = SSUB(HASH,MULTIPLE) + 1
*
LOCATE(KEY,MAP(POS)<1>,1,1;ANYPOS) THEN
FLAG = TRUE
END ELSE
FLAG = FALSE
END
*
RETURN
*
* END OF PROGRAM
*
END
*