SilverScreen Solid Modeler

B-tree Databases

B-tree Databases

Previous topic Next topic  

B-tree Databases

Previous topic Next topic JavaScript is required for the print function  

SilverScreenAPI

 

B-Tree Databases

 

 

 


A b-tree database consists of two files: an index file and a data file. The index file is used to organize information that is stored in the data file. The index file contains a set of keys that are maintained in ascending sequence. Associated with each key is a record number. This record number identifies the record in the data file that is associated with the key.

 

The keys in the index file can be accessed sequentially or randomly. For a given key, the associated record number can be used to retrieve the data file information that is related to that key.

 

Two or more b-trees may be based on a single data file. This allows the information in the data file to be organized in several different ways. For a file containing employee information, one might construct one index to access employee information by employee number, while creating another index to access the information by employee name.

 

The b-tree functions are summarized below.

 


B-tree open, close and flush

Function

Description

bt_open

Open a b-tree

bt_close

Close a b-tree

bt_flush

Flush all b-trees to disk

File creation functions

Function

Description

bt_create_data

Create a data file

bt_create_tree

Create an index file

Index file functions

Function

Description

bt_delete

Delete an entry

bt_find

Find a key

bt_find2

Find key/record

bt_insert

Insert a new entry

bt_next

Retrieve the next entry

bt_previous

Retrieve the previous entry

bt_set_first

Set read marker to beginning of index

bt_set_key

Set read marker to a specific key

bt_set_last

Set read marker to end of index

bt_update

Update an entry

Data file functions

Function

Description

bt_erase

Erase (remove) a record

bt_read

Read a record

bt_store

Store (create) a new record

bt_write

Write (update) a record

 

 


B-trees are created by the bt_create_data and bt_create_tree functions. These functions create an empty data file and an empty index file respectively.

 

When a data file is created, the record size must be specified. If text information is to be stored, then record size should be the length of the longest possible string. If structure information is stored, then record size should be the size of the structure (sizeof <structure name>).

 

Before a b-tree can be accessed, it must be opened with bt_open . This function returns a b-tree handle. Index file functions use this handle to identify the index file, while data file functions use the handle to identify the data file. If two b-trees use a common data file, then either handle can be used to identify the data file.