CPP   39

heapfile

Guest on 22nd August 2022 01:42:44 PM

  1.  
  2. HEAPFILE HEADER FILE
  3. --------------------
  4.  
  5. #ifndef _HEAPFILE_H
  6. #define _HEAPFILE_H
  7.  
  8. #include "minirel.h"
  9. #include "page.h"
  10.  
  11.  
  12. //  This heapfile implementation is directory-based. We maintain a
  13. //  directory of info about the data pages (which are of type HFPage
  14. //  when loaded into memory).  The directory itself is also composed
  15. //  of HFPages, with each record being of type DataPageInfo
  16. //  as defined below.
  17. //
  18. //  The first directory page is a header page for the entire database
  19. //  (it is the one to which our filename is mapped by the DB).
  20. //  All directory pages are in a doubly-linked list of pages, each
  21. //  directory entry points to a single data page, which contains
  22. //  the actual records.
  23. //
  24. //  The heapfile data pages are implemented as slotted pages, with
  25. //  the slots at the front and the records in the back, both growing
  26. //  into the free space in the middle of the page.
  27. //  See the file 'hfpage.h' for specifics on the page implementation.
  28. //
  29. //  We can store roughly pagesize/sizeof(DataPageInfo) records per
  30. //  directory page; for any given HeapFile insertion, it is likely
  31. //  that at least one of those referenced data pages will have
  32. //  enough free space to satisfy the request.
  33.  
  34.  
  35.       // Error codes for HEAPFILE.
  36. enum heapErrCodes {
  37.     BAD_RID,
  38.     BAD_REC_PTR,
  39.     HFILE_EOF,
  40.     INVALID_UPDATE,
  41.     NO_SPACE,
  42.     NO_RECORDS,
  43.     END_OF_PAGE,
  44.     INVALID_SLOTNO,
  45.     ALREADY_DELETED,
  46. };
  47.  
  48. // DataPageInfo: the type of records stored on a directory page:
  49.  
  50. struct DataPageInfo {
  51.   int    availspace;  // HFPage returns int for avail space, so we use int here
  52.   int    recct;       // for efficient implementation of getRecCnt()
  53.   PageId pageId;      // obvious: id of this particular data page (a HFPage)
  54. };
  55.  
  56. class HFPage;
  57.  
  58.  
  59. class HeapFile {
  60.  
  61.   friend class Scan;
  62.  
  63.   public:
  64.       // Initialize.  A null name produces a temporary heapfile which will be
  65.       // deleted by the destructor.  If the name already denotes a file, the
  66.       // file is opened; otherwise, a new empty file is created.
  67.     HeapFile( const char *name, Status& returnStatus );
  68.    ~HeapFile();
  69.  
  70.       // return number of records in file
  71.     int getRecCnt();
  72.    
  73.       // insert record into file
  74.     Status insertRecord(char *recPtr, int recLen, RID& outRid);
  75.    
  76.       // delete record from file
  77.     Status deleteRecord(const RID& rid);
  78.  
  79.       // updates the specified record in the heapfile.
  80.     Status updateRecord(const RID& rid, char *recPtr, int reclen);
  81.  
  82.       // read record from file, returning pointer and length
  83.     Status getRecord(const RID& rid, char *recPtr, int& recLen);
  84.  
  85.       // initiate a sequential scan
  86.     class Scan *openScan(Status& status);
  87.  
  88.       // delete the file from the database
  89.     Status deleteFile();
  90.  
  91.  
  92.   private:
  93.  
  94. };
  95.  
  96.  
  97. #endif    // _HEAPFILE_H

Raw Paste


Login or Register to edit or fork this paste. It's free.