// 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 using namespace std; #include "Bucket.h" class Bucket; class Directory { public: Directory(int maxBucketKeys); ~Directory(); int Depth_length; int BucketAddress_length; int Create(char *dirFileName, char *bucketFileName,char *logFileName); // create an empty extendible hashing index int Open(char *dirFileName, char *bucketFileName, char *logFileName); // open an existing extendible hashing index int OpenForSearch(char *dirFileName, char *bucketFileName); // open an existing extendible hashing index int Close(); // close an existing extendible hashing index int CloseSearch(); // 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 NumCells; // = 2^Depth int *BucketAddr; int Depth; int Restributing; int LogCounter; // array of bucket addresses to be allocated fstream DirectoryFile; // logical name for directory file fstream BucketFile; // logical name for bucket file fstream BucketFileAdd; // logical name for bucket file fstream LogFile; // log file Bucket * CurrentBucket; // pointer to current bucket int DoubleSize(); // doubles the size of the directory int InsertBucket (Bucket * bucket,int bucketAddr, int Index); // change directory cells to refer to this bucket int Find (long key); // return bucket address for key int StoreBucket (Bucket * bucket,long key, int recAddr,int position); // 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