Finish part 1

This commit is contained in:
Max O'Cull 2019-03-28 22:35:58 -04:00
parent 732977b4fa
commit a9a58d2cbd
4 changed files with 68 additions and 22 deletions

View File

@ -1,7 +1,9 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5 org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.processAnnotations=disabled org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.5 org.eclipse.jdt.core.compiler.source=1.5

View File

@ -12,7 +12,7 @@ public class FileScan extends Iterator {
private HeapFile file = null; // needed for restart(), getFile(); private HeapFile file = null; // needed for restart(), getFile();
private HeapScan scan = null; private HeapScan scan = null;
private RID rid = null; private RID rid = null;
private boolean isOpen; private boolean isOpen = false;
/** /**
* Constructs a file scan, given the schema and heap file. * Constructs a file scan, given the schema and heap file.

View File

@ -1,5 +1,7 @@
package relop; package relop;
import global.RID;
import index.BucketScan;
import global.SearchKey; import global.SearchKey;
import heap.HeapFile; import heap.HeapFile;
import index.HashIndex; import index.HashIndex;
@ -8,13 +10,21 @@ import index.HashIndex;
* Wrapper for bucket scan, an index access method. * Wrapper for bucket scan, an index access method.
*/ */
public class IndexScan extends Iterator { public class IndexScan extends Iterator {
private HeapFile file = null;
private BucketScan scan = null;
private HashIndex index = null;
private boolean isOpen = false;
/** /**
* Constructs an index scan, given the hash index and schema. * Constructs an index scan, given the hash index and schema.
*/ */
public IndexScan(Schema schema, HashIndex index, HeapFile file) { public IndexScan(Schema schema, HashIndex index, HeapFile file) {
throw new UnsupportedOperationException("Not implemented"); this.file = file;
this.schema = schema;
this.index = index;
this.scan = this.index.openScan();
this.isOpen = true;
} }
/** /**
@ -29,28 +39,42 @@ public class IndexScan extends Iterator {
* Restarts the iterator, i.e. as if it were just constructed. * Restarts the iterator, i.e. as if it were just constructed.
*/ */
public void restart() { public void restart() {
throw new UnsupportedOperationException("Not implemented"); if (this.isOpen()) {
scan.close();
this.isOpen = false;
}
this.scan = this.index.openScan();
this.isOpen = true;
} }
/** /**
* Returns true if the iterator is open; false otherwise. * Returns true if the iterator is open; false otherwise.
*/ */
public boolean isOpen() { public boolean isOpen() {
throw new UnsupportedOperationException("Not implemented"); return this.isOpen;
} }
/** /**
* Closes the iterator, releasing any resources (i.e. pinned pages). * Closes the iterator, releasing any resources (i.e. pinned pages).
*/ */
public void close() { 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. * Returns true if there are more tuples, false otherwise.
*/ */
public boolean hasNext() { public boolean hasNext() {
throw new UnsupportedOperationException("Not implemented"); if (this.isOpen()) {
return this.scan.hasNext();
}
return false;
} }
/** /**
@ -59,14 +83,21 @@ public class IndexScan extends Iterator {
* @throws IllegalStateException if no more tuples * @throws IllegalStateException if no more tuples
*/ */
public Tuple getNext() { public Tuple getNext() {
throw new UnsupportedOperationException("Not implemented"); if (this.isOpen()) {
RID rid = this.scan.getNext();
byte[] data = this.file.selectRecord(rid);
Tuple tuple = new Tuple(this.getSchema(), data);
return tuple;
}
return null;
} }
/** /**
* Gets the key of the last tuple returned. * Gets the key of the last tuple returned.
*/ */
public SearchKey getLastKey() { public SearchKey getLastKey() {
throw new UnsupportedOperationException("Not implemented"); return this.scan.getLastKey();
} }
/** /**
@ -74,7 +105,7 @@ public class IndexScan extends Iterator {
* number of buckets if none. * number of buckets if none.
*/ */
public int getNextHash() { public int getNextHash() {
throw new UnsupportedOperationException("Not implemented"); return this.scan.getNextHash();
} }
} // public class IndexScan extends Iterator } // public class IndexScan extends Iterator

View File

@ -1,5 +1,6 @@
package relop; package relop;
import global.RID;
import global.SearchKey; import global.SearchKey;
import heap.HeapFile; import heap.HeapFile;
import index.HashIndex; import index.HashIndex;
@ -67,7 +68,11 @@ public class KeyScan extends Iterator {
* Returns true if there are more tuples, false otherwise. * Returns true if there are more tuples, false otherwise.
*/ */
public boolean hasNext() { public boolean hasNext() {
throw new UnsupportedOperationException("Not implemented"); if (this.isOpen()) {
return this.scan.hasNext();
}
return false;
} }
/** /**
@ -76,7 +81,15 @@ public class KeyScan extends Iterator {
* @throws IllegalStateException if no more tuples * @throws IllegalStateException if no more tuples
*/ */
public Tuple getNext() { public Tuple getNext() {
throw new UnsupportedOperationException("Not implemented"); if (this.isOpen()) {
RID rid = scan.getNext();
byte[] data = this.file.selectRecord(rid);
Tuple tuple = new Tuple(this.getSchema(), data);
return tuple;
}
return null;
} }
} // public class KeyScan extends Iterator } // public class KeyScan extends Iterator