home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
EFFO
/
forum3.lzh
/
btree.doc
next >
Wrap
Text File
|
1987-11-06
|
9KB
|
297 lines
O.E.Tutzauer
Willibrachtstr. 13
6000 Frankfurt 50
(069)-528495
BTREE findet sich zwar in vielen Public-Domain-Sammlungen, ist aber
anscheinend NICHT MEHR Public Domain Software, sondern wird gegen
einen "modesten" Betrag ($65 ?) verkauft. Fⁿr Applikationen wird
keine Royalty verlangt. Versehentlich habe ich Michael BΣhr die
falsche Diskette gegeben (eine Σltere Version ohne ISAM ist auf
CUG#155 zu finden).
Wenn Sie Btree und Isam verwenden wollen, sollten Sie mit dem Autor
Kontakt aufnehmen:
SOFTFOCUS
1343 Stanbury Drive
Oakville, Ontario, Canada L6L 2J5
(416) 825.0903
Der folgende Text ist aus seinen Prospekten abgeschrieben, die
Informationen finden sich aber auch im Source. ynad kann sehr leicht
fⁿr eigene Zwecke umgeschrieben werden; die volle Leistung zeigt
das Programm, wenn es in der RAM-Disk lΣuft (ich verwende ein
Start-Procedurefile zum Kopieren und ein Quit-File zum Zurⁿck-
schreiben der Daten; vorher werden die Files auf Diskette in "old.."
umbenannt). Leider haben die Amerikaner (noch) keine Umlaute.
*** ▄brigens: bei den alten Laufwerken passiert es ÷fters (ca. 15%),
da▀ bei rename das erste File ⁿbersprungen wird. Hat wahr-
scheinlich etwas mit der Synchronisierung zu tun.
BTREE (softfocus)
ISAM (softfocus)
BTREE LIBRARY DESIGN PHILOSOPHY
The BTree Library is a set of file management routines that integrate
with C applications. It provides the programmer with a powerful and
easy to use method of performing all necessary random and sequential
file processing. This frees the application designer to concentrate on
higher level program details, knowing that the file system interface is
sound.
The index algorithm used is based on a pure B-tree with certain
enhancements to speed up sequential key access. All expected index and
data file operations are supported, including addition, random and
sequential access, and deletion. All indices are perfectly balanced at
all times. Depleted space is reclaimed automatically and no "pack"
operation is ever required.
Index and data file operations are logically separated. Each entry in an
index contains its key value and a long data record pointer. Typically
this pointer will refer to an existing data record, but the programmer
is free to build any index/data file relationship desired. Indices and
data files can exist independent of each other. There is no built-in
limit to the number of keys that can refer to a given file OR the number
of files that may be referred to by a given index.
ISAM DRIVER
The softfocus ISAM Driver is a high level interface to the BTree
library. Where the BTree library makes no assumptions about the
relationship between indices and data files, the ISAM Driver assumes
that the programmer will be working with data records which contain both
key and data information.
The ISAM Driver has been carefully designed to minimize the amount of
attention the programmer must spend on the filesystem. nearly all calls
have indentical format requiring only the integer descriptor of the
filesystem and a pointer to a structure to read and writefrom.
Within a simple inventory system the main inventory file could look
something like this:
struct {
char ParCode[6]; /* key field */
char Dec[31]; /* data */
long NumInStock; /* data */
char BinLoc[6]; /* data */
} Inv;
The ISAM Driver will create and maintain such a filesystem; the create
command in this case is this simple:
static int keys[] = 0, 6;
btCreate("invfile",sizeof(Inv), keys);
Now all the programmer has to do to add, delete, or update records is
copy the appropriate values into the Inv structure and issue the
required ISAM call. For example, to read the part coded 'part1', only
the following code is required:
strcpy(Inv.PartCode, "part1");
btRead(fd, &Inv);
The description field can be changed and the record rewritten as
follows:
strcpy(Inv.Desc, "New Description");
btWrite(fd, &Inv);
All indices are always correctly updated by any ISAM operations that
change key values. Below is an example of changing a key field:
strcpy(Inv.PartCode, "part1");
btFind(fd, &Inv);
strcpy(Inv.PartCode, "1Part");
btWrite(fd, &Inv);
Multiple indices can be defined for any filesystem. The following code
will build a new index base on the BinLoc field and read through that
file in that order. (This would be very handy around inventory time!).
btAddInx(fd, &Inv.BinCode - &Inv, TRUE);
btSelect(fd, 1);
btFirst(fd, &Inv);
while ( btFPos() != EOF) {
/* process here */
btNext(fd, &Inv);
}
If an index is no longer required, it can be deleted with one call:
btDelInx(fd, 1);
ISAM SPECIFICATIONS
Most ISAM Driver limitations are those imposed by the BTree library. the
number of concurrently open filesystems allowed can be set by an
internal #define. Each open filesystem will open at least one data file
and one index file.
BTREE LIBRARY SPECIFICATIONS
Maximum key size:
No limit. Set available memory at compile
time. Keys may be any string value.
Maximum data record length
32 kByte per record
Maximum nomber of index entries
16.7 million keys
Maximum number of data entries
16.7 million records
Duplicate key values
Fully supported; keys are stored in the
order entered
Variable length data records
Fully supported by the separate library
vlen.c
Compilers
The BTree Library can be used with any K&R
standard compiler. It is currently being used
with Aztec, DeSmet C, Lattice, MicroSoft, CI86,
Wizard C, and Mark Williams to name a few.
Operating system
The BTree Library is curretly in use on machines
running MS-DOS, CP/M, Unix, Xenix, qnx, venix,
Idris, Macintosh and Tandy operating systems.
Size
The actual object size of the BTree library will
vary depending on what compiler and operating
system are being used. The source file is about
1500 lines long.
BTREE LIBRARY FUNCTIONS
lioAvl() returns the next available data record
number. Deleted space is automatically
reclaimed.
lioClose() close an index or data file
lioCreat() creates a new index or datafile
lioDelete() deletes an existing key and rebalances
the BTree
lioFirst() move to the first key in the given index
lioFlush() flush the file buffers to disk and ensure
that the file is in a safe state
lioFree() release (delete) a data record for reuse
lioInsert() add a new key to the given index
lioNext() move to the next key in the given index
lioOpen() open an existing index or data file
lioRead() read the given data record
lioSearch() search for the given key in the given index
lioSerNum() search for a key having a given data record
number
lioSize() return the size of an index or data file
lioSrPrtl() find the key greater than or equal to the
given value
lioWrite() write a data record
The included variable length data record
library supports the following functions:
vlCreat() create a variable length data filesystem
vlOpen() prepare an existing vlen file system for use
vlClose() close a vlen filesystem
vlFlush() write all buffers to disk and ensure that
the vlen file is in a safe state
vlAvl() allocate a new vlen record number
vlWrite() write a vlen data record. Records of
changed length are handled automatically
vlRead() read the given vlen record
vlFree() release (delete) the given record for
reuse
vlGetErr() return a pointer to an error message
vlStats() return various vlen filesystem statistics.
ISAM DRIVER FUNCTIONS
btCreate() create a new filesystem and define the
initial index
btOpen() prepare an existing file for use
btSync() flush all internal buffers and mark the
filesystem as intact
btAdd() add a new record to a filesystem
btRead() read y record with a key that exactly matches
the one given
btFind() read a record with a key that most closely matches
the one given
btWrite() rewrite an existing record updating all indices
btDelete() remove a record from a filesystem
btStart() move to the first record of a filesystem
btEnd() move to the last record of a filesystem
btNext() read the next record in the filessystem
btPrev() read the previous record in the filesystem
btFPos() return an end of file or beginning of file
position
btSize() returns the number of entries in the
filesystem
btSelect() selects which index to use for all future
searches and filesystem movement
btGetCur() reads a fresh copy of the current record
btSetCur() move directly to the record given a the
passed record pointer
btAddInx() defines and creates a new index
btdelInx() deletes an existing index