Figure 1 shows what a BTreeFile with only one BTLeafPage looks like; the single leaf page is also the
root. Note that there is no BTIndexPage in this case.
Figure 2 shows a tree with a few BTLeafPages,
and this can easily be extended to contain multiple levels of BTIndexPages as well.
3.3.1 IndexFile and IndexFileScan
A BTree is one particular type of index. There are other types, for example a Hash index. However,
all index types have some basic functionality in common. We've taken this basic index functionality
and created a virtual base class called IndexFile. You won't write any code for IndexFile. However, any
class derived from an IndexFile should support IndexFile(), Delete(), and insert(). (IndexFile
and IndexFileScan are defined in include/index.h).
Likewise, an IndexFileScan is a virtual base class that contains the basic functionality all index file
scans should support.
3.3.2 BTreeFile
The main class to be implemented for this assignment is BTreeFile. BTreeFile is a derived class of the
IndexFile class, which means a BTreeFile is a kind of IndexFile. However, since IndexFile is a virtual
base class all of the methods associated with IndexFile must be implemented for BTreeFile. You should
have copied btfile.h into your directory, as per the instructions in Section 2.
The methods to be implemented include:
BTreeFile::BTreeFile There are two constructors for BTreeFile (as defined in btfile.h):
one that will only open an index,
and another that will create a new index on disk, with a given type and key size. Observe that the
key type is passed as a value of type AttrType. For this assignment, you only need to handle keys
of type attrString and attrInteger. If there is a call with a key whose type is not one of the two,
return an error.
BTreeFile::insert The BTreeFile::insert method takes two arguments: (a pointer to) a key and
the rid of a data record. The data entry to be inserted---i.e., a `record' in the leaf pages of the
BTreeFile ---consists of the pair [key, rid of data record].
If a page overflows (i.e., no space for the new entry), you should split the page. You may have to
insert additional entries of the form [key, id of child page] into the higher level index pages as part
of a split. Note that this could recursively go all the way up to the root, possibly resulting in a
split of the root node of the B+ tree.
BTreeFile::Delete The BTreeFile::Delete routine simply removes the entry from the appropriate
BTLeafPage. You are not required to implement redistribution or page merging when the number
of entries falls below threshold.
3.3.3 BTreeFileScan
Finally, you will implement scans that return data entries from the leaf pages of the tree. You will
create the scan through a member function of BTreeFile (BtreeFile::new_scan(...) as defined
in btfile.h).
The parameters passed to new_scan() specify the range of keys that will be scanned in the B+ tree.
They are explained in detail in btfile.h.
In the Buffer Manager assignment, you learned how to use the Minibase error protocol. Reviewing it now would be a good
idea. In that assignment, all the errors you returned belonged to one of the categories in new error.h, namely
BUFMGR. In this assignment, you will need to use BTREE, BTLEAFPAGE, and BTINDEXPAGE.
You are required to turn in your copy of all source files through the online secure site https://www.cs.ucr.edu, this includes all the files needed to make this phase and
run the test program. The TAs should be able to go to your handin directory
and type make and run the program.
Please remember late submissions will not be accepted. Make sure to
start early!
This assignment is significantly more difficult than the first three; not only does it
build upon your understanding of the previous two coding assignments (as you must make use of both the Page classes and the Buffer
Manager), you are also also called upon to implement a rather intricate data structure.
Accordingly, we have given you extra time to complete this part of the project. You have roughly three weeks, and you will need them.
If you don't start working on this assignment today,
you're already behind.
|