🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.lang.basic
Article #731

Re: DESPERATE: Indexed files in QBasic ??

#731
From: Judson McClendon
Date: Tue, 24 Feb 1998 00:00
44 lines
3114 bytes
Seamus BROWNE <partage@wanadoo.fr> wrote:
> Hi,
> I have written a few progs with Qbasic.
> Some of them need to lookup data and find an equivalence:
> say , in a table with two fields Refno and Title,
> lookup the Refno "12345" and retrieve Title  "War and Peace".
> 
> I do this using DATA and READ to build a DIM table then
> run along down the DIM table till I find the Refno an dthen grab the Title.
> 
> This may be a slow way of doing things but I can find any other way.
> So ...
> Q1. Is there no way to have an Indexed file in Qbasic ?
> Q2. Is there any other Basic that woul do the job OK without me having to
> re-write my progs?

A fairly straightforward way to do what you want is to maintain a sorted
index into your data file.  The data file would be stored as a RANDOM file,
and the index (also a RANDOM file) would contain the key and the record
number of the data record the key refers to.  As you add records, insert
their keys and record numbers into a sorted memory table of the new keys,
and at EOJ merge the old sorted index file with the sorted memory table,
creating an updated index.  As you delete records, mark their index records
as deleted, or remove them from the memory table as appropriate.  To find
a key do a binary search of the memory table first, then if the key is not
found, do a binary search of the index file.  When the key is found, use
the record number to retrieve the data record.  Except for the few seconds
it takes to merge the memory table with the old index, this is a very fast
and efficient solution.  Because the memory table will be limited in size,
you must force an index update to clear the memory table if so many records
are added that it overflows.

If the data records are not too large you can keep the whole data file in
sequence using this method, but you would have only one search key.  Using
index files, you can have multiple keys.  If the index file is not too
large, you can read the entire index into memory when the file is opened,
maintain the index in memory, and write it out to disk when you close the
file.
-- 
Judson McClendon          This is a faithful saying and worthy of all
Sun Valley Systems        acceptance, that Christ Jesus came into the
judmczzz@mindspring.com   world to save sinners  (1 Timothy 1:15)
(please remove zzz from email id to respond)
Technical Details
Message-ID: <01bd4134$5c6d1740$a6f210d1@juddesk>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <6cukjr$rrc$1@peuplier.wanadoo.fr>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10c949,65d4745eb428207a
X-Google-Attributes: gid10c949,public
X-Google-Thread: fec0a,65d4745eb428207a
X-Google-Attributes: gidfec0a,public
X-Google-Thread: 10ab99,65d4745eb428207a
X-Google-Attributes: gid10ab99,public
X-Google-Thread: f7646,65d4745eb428207a
X-Google-Attributes: gidf7646,public
From: "Judson McClendon" <judmczzz@mindspring.com>
Subject: Re: DESPERATE: Indexed files in QBasic ??
Date: 1998/02/24
Message-ID: <01bd4134$5c6d1740$a6f210d1@juddesk>
X-Deja-AN: 328183903
References: <6cukjr$rrc$1@peuplier.wanadoo.fr>
Organization: Sun Valley Systems
Newsgroups: alt.lang.basic,alt.lang.powerbasic,comp.lang.basic.misc,fr.comp.lang.basic