Homework 2 -- B+ tree search

Preparation

Execute the following commands

This should copy six files into your directory.

The mission

You are going to write a program to search a B+ tree. The record format is the same used in Homework 1. The records will be stored in 128-byte nodes that will consist of a 16-byte header followed by seven 16-byte records.

A definition of an appropriate C data structure for the record and nodes can be found in the file btree.h which you copied by executing the commands above.

You also copied a complete top-level main routine for this assignment. You'll find this code in bsearch.c. This routine will open the file /usr/local/csci/343/testdata/prog02.bt and call the routine btreeSearch which you must write. The btreeSearch routine takes three parameters

Parameter Purpose
dbFile The opened B+ tree file
key The key to search for
val The address of an integer field in which the search result should be stored

btreeSearchshould return 0, if a record matching the key is not in the B+ tree, and 1, if there is a matching record. You'll find a "stub" for implementing btreeSearchin btsearch.c.

Suggested implementation

There are three other files you copied. A stub for implementing a routine readBlockthat reads a single 128-byte block from the B+ tree is found in btio.c, and stubs for implementing routine SearchLeaffor finding a record within a leaf node and routine SearchIntfor finding the pointer to the appropriate B+ subtree are found in btmisc.c. Finally, there is an appropriate Makefilefor compiling and linking these file C files.

The four routines that you must implement are quite small. None should require more than eight lines of C code.

Testing the program

Once your executable program has been generated, you can run the driver routine with commands of the following format.

where keyis the key of the record you are searching for.

Due dates and turning it in

On Wednesday, 6 May, a script will be run to copy your csci/343/home2directory. This script will be run at noon for five consecutive days. Each day your program is missing or fails to successfully solve the problem, 20% will be deducted from your grade for homework two.


Back to the CSCI 363 homework page
Back to the CSCI 363 home page