)
is the library interface to database files.
One of the supported file formats is btree files.
The general description of the database access methods is in
dbopen(3),
this manual page describes only the btree specific information.
The btree data structure is a sorted, balanced tree structure storing associated key/data pairs.
The btree access method specific data structure provided to
dbopen()
is defined in the
<
db.h
>
include file as follows:
typedef struct {
u_long flags;
u_int cachesize;
int maxkeypage;
int minkeypage;
u_int psize;
int (*compare)(const DBT *key1, const DBT *key2);
size_t (*prefix)(const DBT *key1, const DBT *key2);
int lorder;
} BTREEINFO;
The elements of this structure are as follows:
flags
R_DUP
R_NOOVERWRITE
flag is specified.
The
R_DUP
flag is overridden by the
R_NOOVERWRITE
flag, and if the
R_NOOVERWRITE
flag is specified, attempts to insert duplicate keys into the tree
will fail.
If the database contains duplicate keys, the order of retrieval of
key/data pairs is undefined if the
get
routine is used, however,
seq
routine calls with the
R_CURSOR
flag set will always return the logical
``first''
of any group of duplicate keys.
cachesize
cachesize
is 0 (no size is specified) a default cache is used.
maxkeypage
minkeypage
minkeypage
value, it will be stored on overflow pages instead of in the page
itself.
If
minkeypage
is 0 (no minimum number of keys is specified) a value of 2 is used.
psize
psize
is 0 (no page size is specified) a page size is chosen based on the
underlying file system I/O block size.
compare
compare
is
NULL
(no comparison function is specified), the keys are compared
lexically, with shorter keys considered less than longer keys.
prefix
prefix
is
NULL
(no prefix function is specified),
and
no comparison function is specified, a default lexical comparison
routine is used.
If
prefix
is
NULL
and a comparison routine is specified, no prefix comparison is done.
lorder
lorder
is 0 (no order is specified) the current host order is used.
If the file already exists (and the
O_TRUNC
flag is not specified), the values specified for the parameters flags,
lorder and psize are ignored in favor of the values used when the tree
was created.
Forward sequential scans of a tree are from the least key to the greatest.
Space freed up by deleting key/data pairs from the tree is never reclaimed, although it is normally made available for reuse. This means that the btree storage structure is grow-only. The only solutions are to avoid excessive deletions, or to create a fresh tree periodically from a scan of an existing one.
Searches, insertions, and deletions in a btree will all complete in O lg base N where base is the average fill factor. Often, inserting ordered data into btrees results in a low fill factor. This implementation has been modified to make ordered insertion the best case, resulting in a much better than normal page fill factor.