Click on the banner to return to the Class Reference home page.

©Copyright 1996 Rogue Wave Software

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:

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 createMode to set whether to use an existing tree (creating one if one doesn't exist) or to force the creation of a new tree. The location of the resultant root node can be retrieved using member function baseLocation().

More than one B-tree can exist in a disk file. Each must have its own separate root node. This can be done by constructing more than one RWBTreeOnDisk, each with createMode set to create.

The order of the B-tree can be set in the constructor. Larger values will result in shallower trees, but less efficient use of disk space. The minimum number of entries in a node can also be set. Smaller values may result in less time spent balancing the tree, but less efficient use of disk space.

Persistence

None

Enumerations

enum styleMode {V6Style, V5Style};
enum createMode {autoCreate, create};

Public Constructor

RWBTreeOnDisk(RWFileManager& f,
              unsigned nbuf        = 10,
              createMode omode     = autoCreate,
              unsigned keylen      = 16,
              RWBoolean ignoreNull = FALSE,
              RWoffset start       = RWNIL,
              styleMode smode      = V6Style,
              unsigned halfOrder   = 10,
              unsigned minFill     = 10);

Public Member Functions

void
applyToKeyAndValue((*ap)(const char*,RWstoredValue), void* x);
RWoffset
baseLocation() const;
unsigned
cacheCount() const;
unsigned
cacheCount(unsigned newcount);
void
clear();
RWBoolean
contains(const char* ky) const;
size_t
entries();
RWoffset
extraLocation(RWoffset newlocation);
RWBoolean
findKey( const char* ky, RWCString& foundKy)const ;
RWBoolean
findKeyAndValue( const char* ky,
                 RWCString& foundKy,
                 RWStoredValue& foundVal)const ;
RWstoredValue
findValue(const char* ky)const;
int
height();
int
insertKeyAndValue(const char* ky,RWstoredValue v);
unsigned
keyLength() const;
unsigned
minOrder()const;
unsigned
nodeSize() const;
unsigned
order()const;
RWBoolean
isEmpty() const;
void
remove(const char* ky);
RWBoolean
replaceValue(const RWCString& key,
             const RWstoredValue newval,
             RWstoredValue& oldVal);
RWdiskTreeCompare
setComparison(RWdiskTreeCompare fun);