beautypg.com

HP Integrity NonStop J-Series User Manual

Page 98

background image

//1 The program accepts names until encountering an EOF.

//2 The name is used as a key to

RWBTreeOnDisk

, which returns the associated value, an

offset, into the file.

//3 Check to see whether the name was found.

//4 If the name is valid, use the value to seek to the spot where the associated birthdate is

stored.

//5 Read the birthdate from the file.

//6 Print it out.

With a little effort, you can easily 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
#include

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.baseLocation();
}
fm.SeekTo(fm.start());
fm.Write(rootArray, 3);
return 0;
}

And here is how you could open the three B-trees:

#include
#include

main(){
RWoffset rootArray[3]; // Location of the tree roots
RWBTreeOnDisk* treeArray[3]; // Pointers to the RWBTreeOnDisks

RWFileManager fm("index.dat");

This manual is related to the following products: