Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Essential Tools Module Reference Guide

RWBTreeOnDisk

Module:  Essential Tools Module   Group:  File System


Does not inherit

Local Index

Members

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 Destructor

virtual ~RWBTreeOnDisk();

Public Member Functions

void
applyToKeyAndValue((*ap)(const char*,RWstoredValue,void*),
                         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
find(const char* ky)const ;
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);
RWBoolean
isEmpty() const;
unsigned
keyLength() const;
unsigned
minOrder()const;
unsigned
nodeSize() const;
unsigned
occurrencesOf(const char* ky) const;
unsigned
order()const;
void
remove(const char* ky);
RWBoolean
removeKeyAndValue(const char* ky, 
                  RWCString& retKey, 
                  RWstoredValue& retVal);
RWBoolean
removeKeyAndValue(const char* ky
                  RWstoredValue& retVal);
RWBoolean
replaceValue(const RWCString& key,
             const RWstoredValue newval,
             RWstoredValue& oldVal);
RWdiskTreeCompare
setComparison(RWdiskTreeCompare fun);


Previous fileTop of DocumentContentsIndex pageNext file

©2004 Copyright Quovadx, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Quovadx, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.