Des morceaux de codes donnes pour le devoir 3 sont ci-bas. Pour reprende le code donne dans le livre afin de le modifier et l'adapter a vos besoins, vous pouvez aller au site FTP indique dans la preface du livre (ftp.aw.com/cseng/authors/riccardi) par FTP anonyme. ------------------------------------------------------------------------------- // Bucket.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. // Bucket class holds a bucket in main memory #ifndef BUCKET_H #define BUCKET_H #include "Directory.h" class Bucket { protected: // there are no public members, // access to Bucket members is only through class Directory Bucket ( Directory *dir, int maxKeys); int Insert (long key, int dataRecAddr); // may use "char *key" or "string & key" void Split(); // split the bucket and redistribute keys int NewRange (int & newStart, int & newEnd); // calculate the range in directory of new (split) bucket int Redistribute (Bucket & newBucket); // redistribute keys between this and new bucket int Depth; // depth of the bucket // number of bits used in common by keys of this bucket Directory *Dir; // pointer to the directory that contains the bucket int BucketAddr; //address of this bucket in file // include here variable to hold the various (maxKeys) index records in this bucket friend class Directory; // Directory has access to its protected members }; #endif ------------------------------------------------------------------------------- // 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 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