HASHING 8/9

 BBS: Inland Empire Archive
Date: 05-09-92 (01:16)             Number: 193
From: TOM HAMMOND                  Refer#: NONE
  To: LYN BORCHERT                  Recvd: NO  
Subj: HASHING     8/9                Conf: (2) Quik_Bas
Continued from Hashing 7/9

  LoadIt:
  'load the data from a data file

  Free% = 0
  Empty% = Empty% + 1

  FOR I% = 0 TO ArraySize%
      IF a$(I%, 0) = "" THEN
         Free% = Free% + 1
         Empty% = Empty% + 1

      ELSEIF a$(I%, 0) = DeletedValue$ THEN
         Free% = Free% + 1
      END IF
  NEXT I%

  IF Empty% = 0 THEN
     GOSUB SorryFull

  ELSE
     INPUT "File To Load From:"; FileName$
     ON ERROR GOTO ErrorHandler
     Found = True
     OPEN FileName$ FOR INPUT AS 1

     IF Found = True THEN
        DO WHILE NOT EOF(1) AND Free% > 0
       INPUT #1, TestName$, PhoneNumber$
       CALL GetData(TestName$, Index%, Seeks%, SaveIndex%)

       IF SeekCount% >= RetryLimit% THEN
          PRINT "The data base is full and/or needs to be resized"
          YesOrNo$ = ""
          DO WHILE YesOrNo$ <> "Y" AND YesOrNo$ <> "N"
             INPUT "Do you want to see a data base dump (Y/N)"; YesOrNo$
             IF YesOrNo$ <> "" THEN
            YesOrNo$ = WhackIt$(YesOrNo$)
             END IF
             IF YesOrNo$ = "Y" THEN
            GOSUB DumpIt
             ELSEIF YesOrNo$ <> "N" THEN
            PRINT "Please Enter A Y for Yes or a N for NO."
             END IF
          LOOP

          Free% = 0 'force a shutdown
          CALL Waiter

       ELSEIF a$(Index%, 0) = TestName$ THEN
          ' the value is already on file
          ' we'll just replace the old value for now,
          ' and keep on truckin - we could ask the user
          ' what we should do, but not for a test program!
          a$(Index%, 1) = PhoneNumber$
          PRINT a$(Index%, 0); "has been updated!"

       ELSE
          IF SaveIndex% <> -1 THEN
             'reuse deleted space
             Index% = SaveIndex%
             PRINT "We are reclaiming unused space!  Ain't it great!"
          END IF
          a$(Index%, 0) = TestName$
          a$(Index%, 1) = PhoneNumber$
          Free% = Free% - 1
       END IF

       IF Free% < 1 THEN
          PRINT "The data base has been completely filled."
          PRINT "Some data was not loaded from the file you selected."
          PRINT
          GOSUB SorryFull

          CALL Waiter
       END IF
        LOOP
        CLOSE 1
     END IF
     ON ERROR GOTO 0
  END IF

  RETURN

  SaveIt:
  'Save data to a selected file

  ON ERROR GOTO ErrorHandler

  INPUT "Name of file to save data to:"; FileName$

  OPEN FileName$ FOR OUTPUT AS 1
  FOR I% = 0 TO ArraySize%
      IF a$(I%, 0) <> "" AND a$(I%, 0) <> DeletedValue THEN
         PRINT #1, a$(I%, 0); ","; a$(I%, 1)
      END IF
  NEXT I%
  CLOSE 1
  RETURN

  SortIt:
  ' convert, sort, and dump the data base

  'convert the hashed A$() into a packed SortSpace$()

  PRINT "Converting the data into a linear array...."
  NextEntry% = 0
  FOR I% = 0 TO ArraySize%
      IF a$(I%, 0) <> "" AND a$(I%, 0) <> DeletedValue$ THEN
         SortSpace$(NextEntry%, 0) = a$(I%, 0)
         SortSpace$(NextEntry%, 1) = STR$(I%)
         'track the location of the data, not the data....
         NextEntry% = NextEntry% + 1
      END IF
  NEXT I%

Continues in next file (HASHING - 9 of 9)


--- WM v2.00/91-0231
 * Origin: The Modem Zone BBS (314) 893-5106 (1:289/2)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET