diff --git a/p3/max.minibase b/p3/max.minibase new file mode 100644 index 0000000..f96d1dd Binary files /dev/null and b/p3/max.minibase differ diff --git a/p3/src/relop/FileScan.java b/p3/src/relop/FileScan.java index 73ddbcb..04be1cd 100644 --- a/p3/src/relop/FileScan.java +++ b/p3/src/relop/FileScan.java @@ -9,7 +9,6 @@ import heap.HeapScan; * version takes schema into consideration and generates real tuples. */ public class FileScan extends Iterator { - private HeapFile file = null; // needed for restart(), getFile(); private HeapScan scan = null; private RID rid = null; @@ -70,7 +69,7 @@ public class FileScan extends Iterator { /** * Gets the next tuple in the iteration. - * + * * @throws IllegalStateException if no more tuples */ public Tuple getNext() { @@ -83,7 +82,7 @@ public class FileScan extends Iterator { public RID getLastRID() { return rid; } - + // getter; added so HashJoin doesn't have to copy the file; public HeapFile getFile(){ return file; diff --git a/p3/src/relop/KeyScan.java b/p3/src/relop/KeyScan.java index c209be2..f52e068 100644 --- a/p3/src/relop/KeyScan.java +++ b/p3/src/relop/KeyScan.java @@ -9,12 +9,22 @@ import index.HashScan; * Wrapper for hash scan, an index access method. */ public class KeyScan extends Iterator { - + private HeapFile file = null; // needed for restart(), getFile(); + private HashScan scan = null; + private HashIndex index = null; + private SearchKey key = null; + private boolean isOpen; + /** * Constructs an index scan, given the hash index and schema. */ public KeyScan(Schema aSchema, HashIndex aIndex, SearchKey aKey, HeapFile aFile) { - throw new UnsupportedOperationException("Not implemented"); + this.schema = aSchema; + this.index = aIndex; + this.key = aKey; + this.file = aFile; + this.scan = this.index.openScan(this.key); + this.isOpen = true; } /** @@ -22,44 +32,51 @@ public class KeyScan extends Iterator { * child iterators, and increases the indent depth along the way. */ public void explain(int depth) { - throw new UnsupportedOperationException("Not implemented"); + throw new UnsupportedOperationException("Not implemented"); } /** * Restarts the iterator, i.e. as if it were just constructed. */ public void restart() { - throw new UnsupportedOperationException("Not implemented"); + this.isOpen = false; // In case of errors maybe? + this.close(); + this.scan = this.index.openScan(this.key); + this.isOpen = true; } /** * Returns true if the iterator is open; false otherwise. */ public boolean isOpen() { - throw new UnsupportedOperationException("Not implemented"); + return this.isOpen; } /** * Closes the iterator, releasing any resources (i.e. pinned pages). */ public void close() { - throw new UnsupportedOperationException("Not implemented"); + if (this.isOpen()) { + this.scan.close(); + this.scan = null; + this.isOpen = false; + } } /** * Returns true if there are more tuples, false otherwise. */ public boolean hasNext() { - throw new UnsupportedOperationException("Not implemented"); + throw new UnsupportedOperationException("Not implemented"); } /** * Gets the next tuple in the iteration. - * + * * @throws IllegalStateException if no more tuples */ public Tuple getNext() { - throw new UnsupportedOperationException("Not implemented"); + throw new UnsupportedOperationException("Not implemented"); } } // public class KeyScan extends Iterator