BTreeFile is an implementation of a DbFile that stores a B+ tree. Specifically, it stores a pointer to a root page, a set of internal pages, and a set of leaf pages, which contain a collection of tuples in sorted order. BTreeFile works closely with BTreeLeafPage, BTreeInternalPage, and BTreeRootPtrP
| 29 | * @author Becca Taft |
| 30 | */ |
| 31 | public class BTreeFile implements DbFile { |
| 32 | |
| 33 | private final File f; |
| 34 | private final TupleDesc td; |
| 35 | private final int tableid; |
| 36 | private final int keyField; |
| 37 | |
| 38 | /** |
| 39 | * Constructs a B+ tree file backed by the specified file. |
| 40 | * |
| 41 | * @param f - the file that stores the on-disk backing store for this B+ tree |
| 42 | * file. |
| 43 | * @param key - the field which index is keyed on |
| 44 | * @param td - the tuple descriptor of tuples in the file |
| 45 | */ |
| 46 | public BTreeFile(File f, int key, TupleDesc td) { |
| 47 | this.f = f; |
| 48 | this.tableid = f.getAbsoluteFile().hashCode(); |
| 49 | this.keyField = key; |
| 50 | this.td = td; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Returns the File backing this BTreeFile on disk. |
| 55 | */ |
| 56 | public File getFile() { |
| 57 | return f; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Returns an ID uniquely identifying this BTreeFile. Implementation note: |
| 62 | * you will need to generate this tableid somewhere and ensure that each |
| 63 | * BTreeFile has a "unique id," and that you always return the same value for |
| 64 | * a particular BTreeFile. We suggest hashing the absolute file name of the |
| 65 | * file underlying the BTreeFile, i.e. f.getAbsoluteFile().hashCode(). |
| 66 | * |
| 67 | * @return an ID uniquely identifying this BTreeFile. |
| 68 | */ |
| 69 | public int getId() { |
| 70 | return tableid; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Returns the TupleDesc of the table stored in this DbFile. |
| 75 | * |
| 76 | * @return TupleDesc of this DbFile. |
| 77 | */ |
| 78 | public TupleDesc getTupleDesc() { |
| 79 | return td; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Read a page from the file on disk. This should not be called directly |
| 84 | * but should be called from the BufferPool via getPage() |
| 85 | * |
| 86 | * @param pid - the id of the page to read from disk |
| 87 | * @return the page constructed from the contents on disk |
| 88 | */ |
nothing calls this directly
no outgoing calls
no test coverage detected