home *** CD-ROM | disk | FTP | other *** search
- Binary Tree Indexing for QuickBASIC
-
-
-
- Introduction
-
- One of the problems with using hashing functions in indexing is
- the inability to step through the index in sequence, find the
- previous and next keys, and find keys with the smallest and
- largest values. Whilst this is not the only problem, it makes any
- solution to this attractive.
-
- With QuickBASIC, separate libraries of code that could be viewed
- as 'black boxes' became a reality. The code for this library
- (containing separately compiled sub-programs) is in QuickBASIC
- version 2.00, although there doesn't seem to be any reason why
- they couldn't be translated to run under BASICA , or even another
- version of BASIC.
-
- The rest of the document is a description of these routines.
-
- An example program (NAMES.EXE & NAMES.BAS) contains calls to a
- number of sub-programs besides the indexing functions, but
- examination of NAMES.BAS should adequately explain their purpose.
- If you wish to get a copy of these routines (source) , and other
- routines demonstrated in NAMES then write to me (with some sort
- of donation):
-
- Roy Barrow
- 3J 222 Church Street
- Philadelphia
- PA 19107
-
- (215) 922 2557
-
-
- Many thanks extended to Thomas Hanlin III for placing his
- excellent package of assembler routines (ADVBAS27) in the public
- domain. This Library makes QuickBASIC really PERFORM!
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- (c) Copyright Roy Barrow -1- 11-January-1986
-
-
-
-
-
- Binary Tree Indexing for QuickBASIC
-
-
- Limitations.
-
- The index key size may only be between 4 & 255 characters in
- length. There may be a maximum of 32766 keys in the index (by
- amending the pointer system so that it uses SHORT numbers in
- place of integers, this could theoretically be increased to 16
- million or so).
-
- Structure & Naming conventions.
-
- The sub-routines are stored separately in files. These files
- begin with AE. This is the abbreviation for a package of sub-
- routines that I have put together (of which binary indexing is a
- small part). The next three characters are BIT (BInary Tree). The
- last three characters indicate the purpose of the sub-routine.
- The routines themselves all begin with BIT. I've placed them in a
- library (AEBITIDX.LIB) that can be used during linkage. The
- routines are as follows:
-
- A brief description of each routine follows.
-
- BIT.CLOSE Close an index file
- BIT.CREAT Create an index. Prompts user for input.
- BIT.CREATQ Create an index, 'quiet' - parameters passed.
- BIT.FIND Find an key in an index.
- BIT.INS Insert a key into an index.
- BIT.KILL Delete a key from an index.
- BIT.LEFT Find the smallest key in the index.
- BIT.NEXT Find the next key in sequence.
- BIT.OPEN Open an index file.
- BIT.PREV Find the previous key in sequence.
- BIT.RIGHT Find the largest key in sequence.
-
-
-
- Using the indexing routines.
-
- Initially, the index(es) need to be created with either BIT.CREAT
- or BIT.CREAQ. From then on, each usage of the routines must be
- preceded by a call to BIT.OPEN. To write away the header details
- of the index, a call to BIT.CLOSE is needed.
-
- Note, the files AESHARED & AECOMMON need to be included in the
- sub-routines & the application programs respectively.
-
- Maintaining the files that the indexes will reference is up to
- your application. In the example program that I have included,
- calls are made to various 'higher level' disk accessing sub-
- routines. These calls would have to be simulated in your
- programs. Again - source for these is available, we're just
- covering the indexing right now. To place an item in the index,
- you need to pass it's relative record number to BIT.INSERT. When
- searching for a record, BIT.FIND will return this relative record
- number.
-
-
-
- (c) Copyright Roy Barrow -2- 11-January-1986
-
-
-
-
-
- Binary Tree Indexing for QuickBASIC
-
-
- Structure of the Index.
-
- Each index has two files, one is a header file, and the other is
- the index proper. (.HDR and .IDX). The header file contains
- information regarding the structure of the index proper. On
- opening the index, the header file is read into control
- variables, the header is closed, and then the actual index
- opened.
-
- The reverse is accomplished when the index is closed: The index
- closed, the header opened, and the new updated info is written to
- the header file.
-
- Most of the values associated with the index are in declared
- COMMON blocks (AECOMMON & AESHARED). The other values needed in
- these routines are discussed for each CALL (below).
-
-
- The routines.
-
- Two variables, AESB.FATAL% and AESB.WARNING% are active
- throughout the whole system of my AE subroutine package. Suffice
- it to say that if the value of AE.FATAL% is NON ZERO on return
- from a routine, then the program should probably abort. It means
- that not only did the routine fail, it was a failure caused by
- buggy code.
-
- On the other hand, if AE.WARNING% is NON ZERO, then it means that
- the routine failed due to other circumstances. For example, if
- you called BIT.KILL without a proper BIT.FIND first, then
- AE.WARNING% would return an error. That's not a routine problem,
- thats a logic fault!
-
-
-
- bit.close Close an index file
- example: call bit.close(fl%)
- parameters: fl% is the number of the file to close
- returns: none
-
-
- bit.creat Verbose creation of an index file.
- example: call bit.creat
- parameters: none
- returns: none
-
-
- bit.creatq Quiet creation of an index file.
- example: call bit.creatq(fl%,flnm$,key.length%)
- parameters: fl% Index file number
- flnm$ Index name (no extension)
- key.length% Length of key
- returns: none
-
-
-
-
- (c) Copyright Roy Barrow -3- 11-January-1986
-
-
-
-
-
- Binary Tree Indexing for QuickBASIC
-
-
- bit.find Find a key in an index
- example: call bit.find(fl%,kvalue$,rrec%,success%)
- parameters: fl% Index file number
- kvalue$ Key value to find
- returns: rrec% Pointer to indexed file
- success% Set to 1 if successful
-
-
- bit.ins Insert a key into the index
- example: call bit.ins(fl%,kvalue$,rrec%,success%)
- parameters: fl% Index file number
- kvalue$ Key value to insert
- rrec% Pointer to indexed file
- returns: success% Set to 1 if successful
-
-
- bit.kill delete a key from the index.
- example: call bit.kill(fl%,kvalue$,rrec%,success%)
- parameters: fl% Index file number
- kvalue$ Key value to delete
- rrec% Pointer to indexed file
- (unchanged from a call to FIND)
- success% (unchanged from a call to FIND)
- returns: success% Set to 1 if successful
-
-
- bit.left Finds the smallest key in the index
- example: call bit.left(fl%,kvalue$,rrec%,success%)
- parameters: fl% Index file number
- returns: kvalue$ Key value in index
- rrec% Pointer to indexed file
- success% Set to non zero if successful
-
-
- bit.next Find next key in an index
- example: call bit.next(fl%,kvalue$,rrec%,success%)
- parameters: fl% Index file number
- kvalue$ (unchanged from last FIND)
- rrec% (unchanged from last FIND)
- success% (unchanged from last FIND)
- returns: kvalue$ Key value in index
- rrec% Pointer to indexed file
- success% Set to non zero if successful
-
-
-
- bit.open Open an index file
- example: call bit.open(fl%,idxnam$)
- parameters: fl% Index file number
- idxnam$ Name of index header (no extension)
- returns: (check warning)
-
-
-
-
-
-
- (c) Copyright Roy Barrow -4- 11-January-1986
-
-
-
-
-
- Binary Tree Indexing for QuickBASIC
-
-
- bit.prev Find previous key in an index
- example: call bit.next(fl%,kvalue$,rrec%,success%)
- parameters: fl% Index file number
- kvalue$ (unchanged from last FIND)
- rrec% (unchanged from last FIND)
- success% (unchanged from last FIND)
- returns: kvalue$ Key value in index
- rrec% Pointer to indexed file
- success% Set to non zero if successful
-
-
- bit.right Finds the largest key in the index
- example: call bit.right(fl%,kvalue$,rrec%,success%)
- parameters: fl% Index file number
- returns: kvalue$ Key value in index
- rrec% Pointer to indexed file
- success% Set to non zero if successful
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- (c) Copyright Roy Barrow -5- 11-January-1986
-
-
-
-
-