The subroutine btinit.c allows you to initialize a btree database based on configuration parameters.
int btinit(char *dbname, int truncflag, int nodesz, int rcdlen, int keylen, int keyofst, int dletofst);
The following is an example of calling btinit.
retcd = btinit(filename,INITNEW,15,30,10,5,0);
In this example:
User error codes are above 300 million. System error codes are above 400 million.
Integer
The truncate flag tells btinit.c whether to truncate an existing database or not. Truncating an existing database risks the loss of irreplaceable data. The truncate flag is one way to prevent the loss of valuable data.
Possible values for the truncate flag are:
Recommendations for using the truncate flag:
Odd Integer.
The threshold number of records in a btree node, that results in the node being split. In Cormen's terms, nodesz is equal to 2t - 1,
where
Range: 3 - 1023
The records per node needs to be odd, because the middle record is promoted to the parent block during a split.
Integer.
Record length or row length
Range: 1 - 32000
Integer.
The key uniquely identifies each record in the btree. Duplicates are not allowed.
Range: 1 - 32000
Integer.
The location of the key in the record relative to the beginning of the record.
Range: 0 - (32000 minus key-length)
Integer.
The location of the delete byte in the record relative to the beginning of the record.
Range: 0 - (32000 minus 1)
The btree configuration program truncates a btree file, depending on the truncate flag.
Be sure to back up all your data before calling btinit.c.
Binary data is allowed in a record. A record may need to exceed 32000 bytes in length if it's an audio track or video sequence. In this case, you may want to design the btree as an index into a separate audio or video file.
The parameter information is stored in the first 256 bytes of the initialized database. See the btreefmt structure in the bthash.h header file for the placement and format of this data. Please note that the fields from hndl to the end of the structure are temporary, and are not stored on disk.