Tools.h++ Manual

104011 Tandem Computers Incorporated 11-5
11
2. The name is used as a key to the
RWBTreeOnDisk
, which returns the
associated value, an offset into the file.
3. Check to see whether the name was found.
4. If the name was valid, use the value to seek to the spot where the
associated birthday is stored.
5. Read the birthdate from the file.
6. Print it out.
With a little effort it is easy to have more than one B-Tree active in the same
file. This allows you to maintain indexes on more than one key. Here’s how
you would create three B-Trees in the same file:
#include <rw/disktree.h>
#include <rw/filemgr.h>
main()
{
RWoffset rootArray[3];
RWFileManager fm(“index.dat”);
RWoffset rootArrayOffset = fm.allocate(sizeof(rootArray));
for (int itree=0; itree<3; itree++)
{
RWBTreeOnDisk btree(fm, 10, RWBTreeOnDisk::create);
rootArray[itree] = btree.rootLocation();
}
fm.SeekTo(fm.start());
fm.Write(rootArray, 3);
return 0;
}