forked from Krowemoh/TCL-Utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MAP.SET
97 lines (96 loc) · 2.65 KB
/
MAP.SET
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
SUBROUTINE MAP.SET(MAT MAP,SIZE,KEY,VALUE)
*
GIT.FILENAME = 'MAP.SET'
GIT.REPO = 'https://github.com/Krowemoh/TCL-Utilities.git'
*
* VERSION
*
VERSION = '1'
*
@USER1 = 'MAP.SET'
@USER2 = 'MAP.SET'
*
COPIED = VALUE
*
GOSUB SETUP
*
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
*
*TEMP PRINT KEY 'L#15' : HASH 'L#25' : POS 'R#3'
*
IF MAP(POS) = '' THEN
MAP(POS)<1,1> = KEY
GOSUB LOWER
GOSUB LOWER
GOSUB LOWER
MAP(POS)<1,2> = COPIED
*
END ELSE
LOCATE(KEY,MAP(POS)<1>,1;ANYPOS) THEN
GOSUB LOWER
GOSUB LOWER
GOSUB LOWER
MAP(POS)<1,2,ANYPOS> = COPIED
*
END ELSE
MAP(POS)<1,1,-1> = KEY
GOSUB LOWER
GOSUB LOWER
GOSUB LOWER
MAP(POS)<1,2,-1> = COPIED
END
END
*
RETURN
*
********************* S U B R O U T I N E *********************
*
SETUP:NULL
*
HIGH = CHAR(254):CHAR(253):CHAR(252):CHAR(251):CHAR(250):CHAR(249):CHAR(248):CHAR(247):CHAR(246):CHAR(245):CHAR(244):CHAR(243):CHAR(242):CHAR(241):CHAR(240):CHAR(239):CHAR(238):CHAR(237):CHAR(236):CHAR(235):CHAR(234):CHAR(233):CHAR(232):CHAR(231):CHAR(230):CHAR(229):CHAR(228):CHAR(227):CHAR(226):CHAR(225):CHAR(224):CHAR(223):CHAR(222):CHAR(221):CHAR(220):CHAR(219):CHAR(218):CHAR(217):CHAR(216):CHAR(215):CHAR(214):CHAR(213):CHAR(212):CHAR(211):CHAR(210):CHAR(209):CHAR(208):CHAR(207):CHAR(206):CHAR(205):CHAR(204):CHAR(203):CHAR(202):CHAR(201)
*
LOW = CHAR(253):CHAR(252):CHAR(251):CHAR(250):CHAR(249):CHAR(248):CHAR(247):CHAR(246):CHAR(245):CHAR(244):CHAR(243):CHAR(242):CHAR(241):CHAR(240):CHAR(239):CHAR(238):CHAR(237):CHAR(236):CHAR(235):CHAR(234):CHAR(233):CHAR(232):CHAR(231):CHAR(230):CHAR(229):CHAR(228):CHAR(227):CHAR(226):CHAR(225):CHAR(224):CHAR(223):CHAR(222):CHAR(221):CHAR(220):CHAR(219):CHAR(218):CHAR(217):CHAR(216):CHAR(215):CHAR(214):CHAR(213):CHAR(212):CHAR(211):CHAR(210):CHAR(209):CHAR(208):CHAR(207):CHAR(206):CHAR(205):CHAR(204):CHAR(203):CHAR(202):CHAR(201):CHAR(200)
*
RETURN
*
********************* S U B R O U T I N E *********************
*
RAISE:NULL
*
CONVERT LOW TO HIGH IN COPIED
*
RETURN
*
********************* S U B R O U T I N E *********************
*
LOWER:NULL
*
CONVERT HIGH TO LOW IN COPIED
*
RETURN
*
* END OF PROGRAM
*
END
*