How to use B-TREE-P with existing files

If you already have a given data file and update program (such as the NAMES data file and the original GET.NAMES update program in the examples), and you want to start using B-TREE-P to be able to use a browser on your data file (like the BROWSE.NAMES program in the examples), then there are seven steps you have to take.

First, decide how many different ways you want to sort and browse your data. (In other words, how many B-trees the data will need.) The NAMES example file was sorted three different ways: (1) by ZIP by address by company by last name by first name by ID, (2) by company by last name by first name by ID, and (3) by last name by first name by ID, so the NAMES example needed three B-trees.

Second, choose names and node sizes for each B-tree. Pick any string of characters you want for a B-tree name, but it's helpful to use something that describes the type of sort the B-tree maintains. For example, pick a name like ZIP if the B-tree sorts the data file by ZIP code. Unless you're prepared to do a lot of tests and benchmarking experiments, just choose 50 for the node size.

Third, modify the BTPKEY subroutine so that it contains a sorting statement for each B-tree you use. How this is done will be explained later.

Fourth, create a new, empty file (it's simplest just to create a file named B-TREE) for keeping the B-trees in. If some other application is already using B-TREE-P and has already created such a file for storing its B-trees, you can use the same file for your B-trees (as long as your B-trees have different names from the other application's B-trees), and skip this step.

Fifth, modify your data file update program (just like the final version of GET.NAMES) so that it calls BTPINS and BTPDEL each time an item in your data file is created, changed, or deleted. When first experimenting with B-TREE-P, you may want to temporarily skip this step if you just want to try browsing your current data file for awhile.

Sixth, but before you actually start executing your new update program, create and execute a small program like the BUILD example, to select every item in your data file and call BTPINS to insert the item in each B-tree. If your data file is empty, you can skip this step. (If after starting to use B-TREE-P you discover you made a programming error and your B-trees are incorrect, or if the B-tree file is somehow damaged, you can use a CLEAR-FILE command to delete all the items in the B-tree file and redo this step at any time to start over with a fresh B-tree.)

Seventh and last, create a browser similar to the BROWSE.NAMES program, for displaying and searching your data file. How this is done will be explained later.