🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

6 total messages Started by Seamus BROWNE Tue, 24 Feb 1998 00:00
DESPERATE: Indexed files in QBasic ??
#730
Author: Seamus BROWNE
Date: Tue, 24 Feb 1998 00:00
19 lines
1419 bytes
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?

Thanks.
Pls reply by e-mail.
Seamus BROWNE at Partage
Re: DESPERATE: Indexed files in QBasic ??
#731
Author: 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)
Re: DESPERATE: Indexed files in QBasic ??
#732
Author: Cornel Huth
Date: Tue, 24 Feb 1998 00:00
27 lines
1708 bytes

Seamus BROWNE? (partage@wanadoo.fr?) wrote (Tue, 24 Feb 1998 15:17:58 +0100):
>This may be a slow way of doing things but I can find any other way.

If you have a compiler BASIC check out Bullet/DOS 16-bit.  At

        http://40th.com/

Costs about $60:  Includes static LIB for QB45, BASIC7x, C/C++, PB3-3.5 (no
current demo PB version, but tested on 3.0c and 3.5).  That's Bullet 1.27a
(bltq127a.zip for QB45/BASIC7x).

Also available in a 16-bit version for Windows (bltw127.zip).

Also 32-bit versions for OS/2, Win32 (NT/95/3.1x w/Win32), and DOSX32 (DLL
and static LIB).

More info and downloads at the site below.

Needs an intermediate-level programmer as a minimum since it makes use of
pointers.
-- 
 Cornel Huth     MIDI DB - The Ultimate MIDI player
 ***********       XG DSP - DSP control of SW60XG, MU*, AT3DXG
 info@40th.com       Mixers - all SBs, WSS, CS423x, OPL3SAx, AT3DXG
 http://40th.com/      Bullet - database engine: OS/2, Win32, DOS32/16
Re: DESPERATE: Indexed files in QBasic ??
#733
Author: Rick
Date: Tue, 24 Feb 1998 00:00
34 lines
1902 bytes
cornel@40th.com (Cornel Huth) wrote:


>Seamus BROWNE? (partage@wanadoo.fr?) wrote (Tue, 24 Feb 1998 15:17:58 +0100):
>>This may be a slow way of doing things but I can find any other way.

>If you have a compiler BASIC check out Bullet/DOS 16-bit.  At

>        http://40th.com/

>Costs about $60:  Includes static LIB for QB45, BASIC7x, C/C++, PB3-3.5 (no
>current demo PB version, but tested on 3.0c and 3.5).  That's Bullet 1.27a
>(bltq127a.zip for QB45/BASIC7x).

>Also available in a 16-bit version for Windows (bltw127.zip).

>Also 32-bit versions for OS/2, Win32 (NT/95/3.1x w/Win32), and DOSX32 (DLL
>and static LIB).

>More info and downloads at the site below.

>Needs an intermediate-level programmer as a minimum since it makes use of
>pointers.
>-- 
> Cornel Huth     MIDI DB - The Ultimate MIDI player
> ***********       XG DSP - DSP control of SW60XG, MU*, AT3DXG
> info@40th.com       Mixers - all SBs, WSS, CS423x, OPL3SAx, AT3DXG
> http://40th.com/      Bullet - database engine: OS/2, Win32, DOS32/16

And its MORE then worth it!
[I have not said something like that before: so be aware!]

Rick
Re: DESPERATE: Indexed files in QBasic ??
#734
Author: George W. White
Date: Wed, 25 Feb 1998 00:00
30 lines
2140 bytes
Cornel Huth wrote:
> If you have a compiler BASIC check out Bullet/DOS 16-bit.  At
> 
>         http://40th.com/
> 
> Costs about $60:  Includes static LIB for QB45, BASIC7x, C/C++, PB3-3.5 (no
> current demo PB version, but tested on 3.0c and 3.5).  That's Bullet 1.27a
> (bltq127a.zip for QB45/BASIC7x).
> 
> Also available in a 16-bit version for Windows (bltw127.zip).
> 
> Also 32-bit versions for OS/2, Win32 (NT/95/3.1x w/Win32), and DOSX32 (DLL
> and static LIB).
> 
> More info and downloads at the site below.
> 
> Needs an intermediate-level programmer as a minimum since it makes use of
> pointers.
> --
>  Cornel Huth     MIDI DB - The Ultimate MIDI player
>  ***********       XG DSP - DSP control of SW60XG, MU*, AT3DXG
>  info@40th.com       Mixers - all SBs, WSS, CS423x, OPL3SAx, AT3DXG
>  http://40th.com/      Bullet - database engine: OS/2, Win32, DOS32/16

Does your Bullet database engine make use of Btrees? What more can you
tell me about it?

--Deeply Shrouded And Quiet
--Central Control D-Dial #49
Re: DESPERATE: Indexed files in QBasic ??
#735
Author: Michael D. Kersey
Date: Wed, 25 Feb 1998 00:00
52 lines
2886 bytes
Seamus BROWNE 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?
> 
> Thanks.
> Pls reply by e-mail.
> Seamus BROWNE at Partage

How many rows do you have in the table? Unless it is large, your method
is pretty good. Reason is that searching a DIM table in memory is very
fast compared with reading a disk file. 

You could sort the rows in the table in "refno" order and do a binary
search for a match: that would speed up the program. 

Or you could use a "hash" table: 
1) DIM the table so it is the next prime number, say aprime, larger than
the amount of data that you have,
2) READ the inputs and store each of them into the row numbered MOD(
refno,  aprime). This will sometimes cause 2 or more refno's to go to
the same row. This is called a "collision". To handle collisions, if a
row is already occuppied, then search forward until an empty row is
found and put the record there. 

To search the hash table: 
1) compute row = Mod(refno1, aprime)
2) go to that row and get it's refno,
3) if refno=refno1 then you've found the correct row, 
4) otherwise search forward looking for a match to refno.

BTW if, when you search forward, you get to the end of the table, you
"wrap around" to the start of the table. 

A hash table can be very quick. If "aprime" is large, then the table is
sparsely populated and you usually get a "hit" on the first attempt. 

HTH,
Mike Kersey
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads