BBS: Inland Empire Archive Date: 04-11-92 (17:14) Number: 10 From: JEAN CREPEAU Refer#: NONE To: ASA ROSSOFF Recvd: NO Subj: Fast Indexing....? Conf: (2) Quik_Bas
In a message to ALL, ASA ROSSOFF wrote: AR=> I wrote a program to display quotes from a file.... But it's very slow the first time it's run, because it creates an index file... I see programs written in other languages creating similar index files in seconds, while my program takes about 20 minutes.... (for a 360k quote file) AR=> The index file is about 14k for a 360k file... AR=> Here's my code to create the index file... any ideas or suggestions would be GREATLY appreciated... AR=> COOKIE.TXT is simply a text file, and a blank line designates the beginning of a new cookie... I understand why it's so long. You read your text file on a character basis... Use the following sub instead. It recreates your text files by eliminating blank lines. This subroutine takes the input file, and creates to new files (filename.DAT and filename.REF). You should not name your input file with the .DAT or .REF extension. DEFLNG A-Z SUB MAKEINDEX(INFILE$) I=INSTR(INFILE$,"."):IF I THEN F2$=LEFT$(INFILE$,I-1) ELSE F2$=INFILE$ F1$=F2$+".DAT" F2$=F2$+".REF" OPEN INFILE$ FOR INPUT ACCESS READ LOCK WRITE AS #1 OPEN F1$ FOR OUTPUT ACCESS WRITE LOCK READ WRITE AS #2 OPEN F2$ FOR BINARY ACCESS WRITE LOCK READ WRITE AS #3 U$="" WHILE NOT EOF(1) IF LEN(U$)>8192 THEN PUT #3,,U$ U$="" ENDIF LINE INPUT #1,X$ IF LEN(X$) THEN U$=U$+MKL$(LOF(2)+1) PRINT #2,X$ ENDIF WEND PUT #3,,U$ CLOSE END SUB The file #3 is buffered with u$, which is an 8K buffer. The sub runs faster this way. OPEN "FILENAME.DAT" FOR INPUT ACCESS READ LOCK WRITE AS #2 OPEN "FILENAME.REF" ACCESS READ LOCK WRITE AS #3 LEN=4 DIM idx AS LONG ntot=LOF(3)/4 gives the number of quotes in your file GET #3,n,idx These 3 lines give you the nth quote in your file SEEK #2,idx 1 <= n <= ntot LINE INPUT #2,x$ x$ = quote --- * Origin: INTERACESS Montreal (QC) Canada (514) 528-1415 (1:167/280)
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