

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


As was stated in class, your group can choose to complete either assignment. I believe that Assignment #4 is easier, and will be less work , if you are reasonably confident your implementation of Assignment #2 is working. The downside is that Assignment #4 builds on everything else that we’ve done, so it will result in a much more complicated piece of software, which equates to more opportunities for untraceable bugs. If you decide to work on Assignment #3, there is the added incentive that if you complete the Insert function, then you can get 20% extra credit (if it works correctly).
The purpose of this assignment is to finish the implementation of the class DBFile, which encapsulates the management of a single file in your database system. This involves adding one more very simple member function to DBFile, and it also involves implementing the BTree file type.
Here are a few hints on the B+-Tree. When implementing your B+-Tree, don’t maintain pointers from leaf node to leaf node (i.e. links along the bottom of the tree). Doing so will make things harder than they need to be. As discussed in class, this is mostly used for concurrency control and recovery anyway (which we won’t worry about implementing in this class).
Also, you should realize before you start that a B+-Tree file has two kinds of nodes: internal nodes, and leaf nodes. Thus, each page in a B+-Tree file should probably have its type written to first few bytes at the beginning of the page (either IN or LN, or 0 or 1, or however you decide to do it), along with the number of used slots in the page.
Finally, I point out that the easiest way to implement internal nodes might be to assume that INs contain binary representation of Record objects, just like LNs or data pages. The difference is that the schema for the records in INs always has two attributes: a key (the same key that is used for LNs in the BTree file; this key will serve as a partition element) as well as a pointer (which can just be an integer attribute that indicates a block address in the file, corresponding to the child).
Given this, here are the methods that you should implement.
*void Open (char fName, Schema &schema, int fileSize, int firstPos, FileType fType)
Here you need to handle the case where fType is BTree. Your code should already handle the other cases, where fType is Heap or Sorted. Open for a BTree works in exactly the same way as the other two file types.
int Find (Value &key);
Again, here you need to handle the BTree case. If the file is not a BTree, simply default to your code for handling the other file types.
void MoveFirst (Value &key);
You should handle this for all file types. Note that this operation is “new” for this assignment. To implement this operation, simply move the “pointer” to point to the first record in the file.
int GetNext (Record &fillMe);
In this assignment, you need to handle the BTree case of GetNext. Again, if the file is not a BTree, simply default to your previous assignment’s code.
void Insert (Record &insertMe);
Again, handle the BTree case. Use the insertion algorithm described in class. Before you work on the Insert operation for a BTree, you should first handle conversion to a BTree, from a sorted file. Completing the Insert routine will get you up to 20% extra credit on the assignment. A non-working Insert routine will still allow you to get a perfect score on this phase of the assignment (assuming that everything else works fine).
*void Convert (char newName, FileType toWhat, DBFile &newFile, Schema &newSchema, int &fileSize, int &firstPos);
Here, you need to handle the conversion from Heap to BTree, and from Sorted to BTree. For conversion between Heap and Sorted, default to your old code. Note that we will not allow conversion from the BTree type to anything else… even to another BTree with a different schema. Once you have a BTree, you are stuck with it forever! This makes the assignment somewhat simpler.
It turns out that things are also made a bit simpler by the fact that really, you only need to handle the conversion from Sorted to BTree. Why? If someone wants you to convert a file from a Heap to a BTree, you should first use your existing code to convert from Heap to Sorted, and then convert the Sorted file to a BTree.
So, how does the Sorted to BTree conversion work? Here is some fairly detailed pseudocode. Assume that the LNs are held in blocks 0 through N - 1. That is, we have sorted the file, and all of the data is in those blocks. Then call the following recursive routine with the invocation BuildTree (0, N – 1, Root, Max, true). After this call, you will have a B+-Tree with a root positioned at the indicated position. We will talk about this routine a bit in class.