// Directory.h  (You may modify, remove and/or add members)
// This class is a simplification of the one given in the 
// textbook "File Structures" by Folk, Zoellick and Riccardi.
// Directory class contains directory and file information
// for the extendible hashing index
#ifndef DIRECTORY_H
#define DIRECTORY_H
#include "Bucket.h"

class Bucket;

class Directory 
{
public:

Directory(int maxBucketKeys); 
~Directory();

int Create(char *dirFileName, char *bucketFileName); 
   // create an empty extendible hashing index

int Open(char *dirFileName);
   // open an existing extendible hashing index

int Close();
   // close an existing extendible hashing index

int Insert (long key, int datafileRecAddr); 
   // insert the pair (key,datafileRecAddr) into the index
   // may use "char *key" or "string & key" instead of "long key"

int Search (long key); // may use "char *key" or "string & key"
   // return the datafileRecAddr for the given key

void Print (ostream & outfile);
   // print the directory as a compact line to outfile; file is already open

protected:

int Depth;
int NumCells; // = 2^Depth
int * BucketAdrr; 
    // array of bucket addresses to be allocated
fstream DirectoryFile; // logical name for directory file
fstream BucketFile; // logical name for bucket file

Bucket  *currentBucket; // pointer to current bucket

int DoubleSize(); // doubles the size of the directory

int InsertBucket (int bucketAddr, int first, int last);
   // change directory cells to refer to this bucket
int Find (long key); // return bucket address for key

int StoreBucket (Bucket & bucket); 
    // update or append bucket in file
int LoadBucket (Bucket & bucket, int bucketAddr);
    // load bucket from file
int MaxBucketKeys; 
    // for this assignment this will be =5 (initialize in constructor)
      
// the hash function may be included in this class, since it
// will be needed for Find, Search, Insert, etc.
friend class Bucket; // Bucket has access to its protected members
}; 
#endif
