Tools.h++ Manual

104011 Tandem Computers Incorporated 21-43
21
RWBTreeOnDisk
Synopsis
typedef long RWstoredValue;
typedef int (*RWdiskTreeCompare)(const char*,
const char*,
size_t);
#include <rw/disktree.h>
#include <rw/filemgr.h>
RWFileManager fm(”filename.dat”);
RWBTreeOnDisk bt(fm);
Description Class
RWBTreeOnDisk
represents an ordered collection of associations of keys
and values, where the ordering is determined by comparing keys using an
external function. The user can set this function. Duplicate keys are not
allowed. Given a key, the corresponding value can be found.
This class is specifically designed for managing a B-Tree in a disk file. Keys,
defined to be arrays of
chars
, and values, defined by the typedef
RWstoredValue
, are stored and retrieved from a B-Tree. The values can
represent offsets to locations in a file where objects are stored.
The key length is set by the constructor. By default, this value is 16 characters.
By default, keys are null-terminated. However, the tree can be used with
embedded nulls, allowing multibyte and binary data to be used as keys. To do
so you must:
Specify
TRUE
for parameter
ignoreNull
in the constructor (see below);
Make sure all buffers used for keys are at least as long as the key length
(remember, storage and comparison will not stop with a null value);
Use a comparison function (such as
memcmp()
) that ignores nulls.
This class is meant to be used with class
RWFileManager
which manages the
allocation and deallocation of space in a disk file.
When you construct an
RWBTreeOnDisk
you give the location of the root node
in the constructor as argument
start
. If this value is
RWNIL
(the default) then
the location will be retrieved from the
RWFileManager
using function
start()
(see class
RWFileManager
). You can also use the enumeration