BTREE (3)
btree database access method
SYNOPSIS
B
#include <sys/types.h>
#include <db.h>
R
DESCRIPTION
The routine
dbopen
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
The flag value is specified by
or 'ing
any of the following values:
R_DUP
Permit duplicate keys in the tree, i.e. permit insertion if the key to be
inserted already exists in the tree.
The default behavior, as described in
dbopen (3),
is to overwrite a matching key when inserting a new key or to fail if
the 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
A suggested maximum size (in bytes) of the memory cache.
This value is
only
advisory, and the access method will allocate more memory rather than fail.
Since every search examines the root page of the tree, caching the most
recently used pages substantially improves access time.
In addition, physical writes are delayed as long as possible, so a moderate
cache can reduce the number of I/O operations significantly.
Obviously, using a cache increases (but only increases) the likelihood of
corruption or lost data if the system crashes while a tree is being modified.
If
cachesize
is 0 (no size is specified) a default cache is used.
maxkeypage
The maximum number of keys which will be stored on any single page.
Not currently implemented.
|