CLASS HeapFile

#include <heapfile.h>

HeapFile implements a heap file with directory structure as describe in the book.

You only need to know how to use the following methods:

Methods

HeapFile::HeapFile(char *name, Status &s)

Open a heap file with filename name. Create the heap file if it does not exists already. If name is NULL, then create a temporary heap file. s will be set to OK if succesful and FAIL otherwise. For example:

Status s;
 HeapFile *F = new HeapFile ("R", s);
 if (s != OK)
 {
  cerr << "Cannot create new HeapFile R\n";
  exit(1);
 }
.......

delete F;

HeapFile::~HeapFile()

If the heap file is a temporary file, delete it permenantly from the database. Otherwise just close the heap file.
 

Status InsertRecord(char *recPtr, int len, RecordID &rid)

Insert a record at location recPtr of length len bytes into the heap file. rid will be set to the record id of the inserted record.
In the join assignment, you insert a joined record. Therefore, you should first call MakeNewRecord( in join.cpp) to create the joined record, and then insert it.

Status GetRecord(const RecordID &rid, char *recPtr, int &len)

Retrieve the record with record id rid from the heap file. The content of the record will be copied into the memory location pointed to by recPtr, and len will be set to the size of the record in bytes.

Note: recPtr must be allocated enough space before calling!!!

int GetNumOfRecords()

Return the number of records in the heap file.

Scan *OpenScan(Status &s)

Create a scan on this heap file. Return the scan and set s to OK if successfull. Otherwise s will be set to FAIL.