1 REM ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 2 REM : WRITTEN BY R. T. VIZZONE 1979 CREATIVE CONSULTING. : 3 REM : MODIFIED RUNNING ON "STANDARD BASIC". : 4 REM ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 5 REM 6 REM :::::::::::::::::::::::: 7 REM :::: MAIN PROGRAM :::: 8 REM :::::::::::::::::::::::: 9 REM 10 GOSUB 100: REM INTIALIZE 20 GOSUB 800: REM MENU 30 ON SEL GOSUB 300,900,1100,3000,1000,700 40 IF EXIT THEN 60 50 GOTO 20 60 END 70 REM 100 REM :::::::::::::::::::::: 110 REM :::: INITIALIZE :::: 120 REM :::::::::::::::::::::: 125 LHT = 101:LSA = 100: REM DEFINE LENGHTS OF HASH TABLE AND STORAGE ARRAY 130 DIM HT(LHT),SA$(LSA,2) 148 FOR I = 0 TO LSA 150 ::SA$(I,0) = "-1" 160 ::SA$(I,1) = "-1" 170 NEXT I 180 FOR I = 0 TO LHT 190 :HT(I) = -1 200 NEXT I 205 NLOC = - 1:TR = - 1 220 DEF FN FOUND(A) = A + 1 223 REM HOME 230 RETURN 240 REM 300 REM :::::::::::::::::::::::: 310 REM ::::::: ADD :::::::::: 320 REM :::::::::::::::::::::::: 330 REM: HOME 332 REM IS SA$ FILLED$ 335 IF (TR < LSA) THEN 340: REM NO IT'S NOT - CONTINUE 336 REM YES IT IS! QUIT 337 PRINT "NOT ENOUGH ROOM FOR AN ADD." 338 PRINT "PRESS ANY KEY TO CONTINUE";: A$=INKEY$ 339 GOTO 370 340 INPUT "SUBJECT: ";N$ 345 IF N$ = "" THEN 370: REM IF USER QUIT THEN RETURN 347 PRINT "INFO: " 348 PRINT 350 INPUT " ";MISC$ 355 ADD = 1: REM HASH-IN(N$,1,RN) 360 GOSUB 400 365 PRINT "THANK YOU" 367 FOR I = 1 TO 500 : NEXT I: REM WAIT TO READ THANK YOU NOTE 368 TR = TR + 1: REM INCREMENT TOTAL RECORDS VARIABLE (TR) 370 RETURN 380 REM 400 REM ::::::::::::::::::::::: 410 REM : HASH-IN(N$,ADD,RN) : 420 REM : GIVEN N$=NAME & : 430 REM : ADD=0 OR 1 : 440 REM : RETURN RN=RECORD # : 450 REM ::::::::::::::::::::::: 455 REM 457 GOSUB 2000: REM HASH-IT(N$,HASV) 460 COLLISIEN = 0: REM COLLISION FLAG 470 P1 = HASHV: REM P1 NOW POINTS INTO THE HASH TABLE 480 P2 = HT(P1): REM LOOK IN HASH TABLE 485 REM ARE LOCATION CONTENTS EMPTY? 490 IF P2 < > - 1 THEN 600: REM NO - GO CHECK SA$ POINTED TO BY P2 500 IF ADD THEN 520: REM YES - DO AN ADD. 510 RN = - 1: GOTO 650: REM YES BUT, THIS WAS A RETRIVE. RN=-1 FOR a RECORD NOT FOUND. RETURN. 515 REM CHECK TO SEE IF THERE ARE ANY EMPTY LOCATIONS IN SA$ MADE BY A PREVIOUS DELETE 520 IF NOT DFLAG THEN 525 521 FOR I = 0 TO NLOC 522 IF SA$(I,0) = "-1" THEN 529: REM THERE IS ONE - USE IT. 524 NEXT I 525 NLOC = NLOC + 1: REM THERE WASN'T ONE - MOVE THE EMPTY POINTER DOWN. 526 EMPTY = NLOC 527 GOTO 530 529 EMPTY = I:DFLAG = DFLAG - 1: REM USING A PREVIOUSLY DELETED LOCATION DECREMENT TOTAL # OF DELETED LOCATIONS. 530 P2 = EMPTY: REM AT LOCATION POINTED TO BY ENPTY 540 SA$(P2,0) = N$: REM ...STORE KEY. 545 SA$(P2,2) = MISC$: REM ATTACH ITS MISC INFO 560 IF COLLISIEN THEN SA$(P1,1) = STR$(EMPTY): REM THIS IS A COLLISION-ADD - CHANGE POINTERS. 570 IF NOT COLLISIEN THEN HT(P1) = EMPTY: REM THIS A NO COLLISION-ADD. 580 GOTO 650: REM ADD DONE - RETURN 599 REM LOOK IN SA$ FOR A MATCH 600 IF SA$(P2,0) = N$ THEN 640: REM A MATCH - RETURN. 610 P1 = P2:COLLISIEN = 1: REM NO MATCH SET COLUMN FLAG AND 620 P2 = VAL (SA$(P1,1)): REM CHECK THE 2ND CCOLUMN OF SA$ FOR NEXT LOCATION TO SEARCH 630 GOTO 485: REM SEARCH AGAIN. 640 RN = P2: REM RN NOW EQUALS THE LOCATION IN SA$ OF KEY JUST ADDED OR FOUND 650 ADD = 0 660 RETURN 700 REM :::::::::::::::::::::: 710 REM ::::::: EXIT :::::::: 720 REM :::::::::::::::::::::: 730 REM 740 EXIT = 1 750 RETURN 800 REM :::::::::::::::::::::: 810 REM :::::: MENU :::::::: 820 REM :::::::::::::::::::::: 830 REM HOME 840 PRINT "SELECTION MENU" 850 PRINT "1. ADD A SUBJECT" 860 PRINT "2. FIND A SUBJECT" 870 PRINT "3. DELETE A SUBJECT" 875 PRINT "4. LIST ALL SUBJECTS" 879 PRINT "5. UPDATE A SUBJECT" 880 PRINT "6. EXIT PPOGRAM": PRINT : PRINT 890 PRINT "INPUT SELECTION NUMBER PLEASE: "; 892 SEL$=INKEY$ 894 SEL = VAL (SEL$) 896 IF SEL < 1 OR SEL > 6 THEN 830 898 RETURN 900 REM :::::::::::::::::::::: 910 REM :::::: RETRIVE :::::: 920 REM :::::::::::::::::::::: 930 REM 940 REM HOME 950 INPUT "SUBJECT: ";R$ 955 IF R$ = "" THEN 999: REM USER QUITS 960 ADD = 0: N$ = R$: GOSUB 400: REM HASH - IN(R$,0,RN) 980 IF FN FOUND(RN) THEN 990 982 PRINT "I CAN'T FIND IT. PRESS ANY" 983 PRINT "KEY TO GO ON. ";: A$=INKEY$ 984 GOTO 999: REM RETURN 990 PRINT "INFO: " 993 PRINT SA$(RN,2) 994 PRINT "PRESS ANY KEY TO GO ON. ";: 995 A$=INKEY$ 996 REM CALL - 868 999 RETURN 1000 REM ::::::::::::::::::::: 1010 REM :::: UPDATE ::::::: 1020 REM ::::::::::::::::::::: 1030 REM 1040 GOSUB 900: IF NOT FN FOUND(RN) OR R$ = "" THEN 1070: REM IF USER QUIT OR NOT FOUNO THEN RETURN 1041 REM CALL - 868 1042 REM 1047 INPUT MISC$: REM DISPLAY MISC INFO UPDATE WITH CURSOR. 1060 SA$(FOUND,2) = MISC$ 1070 RETURN 1100 REM ::::::::::::::::::::: 1110 REM :::: DELETE ::::::: 1120 REM ::::::::::::::::::::: 1130 REM 1140 GOSUB 900: REM FIND RECORD REQUESTED 1145 IF R$ = "" THEN 1200: REM IF USER QUIT OR 1147 IF NOT FN FOUND(RN) THEN 1200: REM ...RECORD NOT FOUND THEN RETURN. 1150 PRINT "DO YOU WISH TO DELETE THIS INFORMATION ";: A$=UPPER$(INKEY$) 1160 IF A$ = "N" THEN 1200 1170 SA$(RN,0) = "-1": REM ERASE DELETED ENTRY. 1180 FOR I = 1 TO LHT: REM CHECK DELETED ENTRY TO SEE IF... 1185 REM ...IT'S 1ST IN A SERIES OF COLLISIONS. IF SO... 1190 IF HT(I) < > RN THEN 1194: REM ... REPLACE ITS POINTER IN HT WITH ITS COLLISION POINTER FROM ITS 2ND COLUMN 1192 HT(I) = VAL (SA$(RN,1)) 1193 SA$(RN,1) = "-1": GOTO 1195 REM CONSEQUENTLY ERASE ITS 2ND COLUMN. 1194 NEXT I 1195 DFLAG = DFLAG + 1: REM INCREMENT DFLAG TO INDICATE ANOTHER EMPTY LOCATION EXISTS. 1197 TR = TR - 1: IF TR < 0 THEN TR = - 1: REM DECREMENT TOTAL RECORDS, NOT TO BE <-1 1200 RETURN 2000 REM ::::::::::::::::::::::: 2010 REM : HASH-IT(N$,HASHV) : 2020 REM : GIVEN N$, RETURN : 2030 REM : HASHV : 2040 REM ::::::::::::::::::::::: 2042 REM DESCRIBED IN ACCOMPAYING ARTICLE 2045 HASHV = 0 2047 N = LEN (N$) 2050 A(0) = 0:A(1) = 0 2060 FOR I = 1 TO N 2070 ::J = INT ((I / 2 - INT (I / 2)) * 2 + .05) * SGN (I / 2) 2080 ::A = ASC (MID$ (N$, I)) 2090 :A(J) = A(J) + A 2100 NEXT I 2110 HASHV = ( INT ((A(0) / 256 - INT (A(0) / 256)) * 256 + .05) * SGN (A(0) / 256)) + 256 * ( INT ((A(1) / 256 - INT (A(1) / 256)) * 256 + .05) * SGN (A(1) / 256)) 2120 HASHV = INT ((HASHV / LHT - INT (HASHV / LHT)) * LHT + .05) * SGN (HASHV / LHT) 2140 RETURN 3000 REM ::::::::::::::::::::::: 3010 REM :::: LIST ALL :::::: 3020 REM ::::::::::::::::::::::: 3030 REM PRINT ALL ELEMENTS OF SA$ THAT ARE NOT EMPTY (NOT -1) 3035 REM HOME 3040 FOR I = 0 TO NLOC 3045 IF SA$(I,0) = "-1" THEN 3090 3050 PRINT SA$(I,0) 3060 REM IS SCREEN FULL(I.E. IS CURSOR AT BOTTOM OF SCREEN)? 3070 GOTO 3090: REM NO - CONTINUE. 3075 PRINT : REM YES - CHECK WITH USER TO CONTINUE 3080 PRINT "PRESS ANY KEY TO CONTINUE OR 'Q' TO QUIT";: A$=UPPER$(INKEY$): IF A$ = "Q" THEN 3110 3085 REM HOME 3090 NEXT I 3095 PRINT 3100 PRINT "PRESS ANY KEY TO GO ON ";: A$=INKEY$ 3110 RETURN