Question: Complete the TODO in below java code: package heapdb; import java.util.Iterator; import java.util.ArrayList; import java.nio.ByteBuffer; public class TableHeap implements ITable { BlockedFile bfile; Schema schema;
Complete the TODO in below java code: package heapdb;
import java.util.Iterator;
import java.util.ArrayList;
import java.nio.ByteBuffer;
public class TableHeap implements ITable
BlockedFile bfile;
Schema schema;
BitMap bitmap; free, row
int rowsperblock;
Index indexes;
public TableHeapString filename, Schema schema
this.schema schema;
create a new file
write schema to block
write free space bitmap to block
data rows start at block
bfile new BlockedFilefilename true;
ByteBuffer buffer ByteBuffer.wrapnew byte;
buffer.position;
schema.serializebuffer;
set bytes used in the buffer.
buffer.putInt buffer.position;
bfile.writeBlock buffer;
write out BitMap of all s
bitmap new BitMap;
bfile.writeBlock bitmap.getBytes;
rowsperblock schemagetTupleSizeInBytes;
indexes new Indexschemasize;
public TableHeapString filename
open existing file
bfile new BlockedFilefilename false;
read the schema from block
ByteBuffer buffer ByteBuffer.wrapnew byte;
bfile.readBlock buffer;
buffer.limitbuffergetInt;
buffer.position;
schema Schema.deserializebuffer;
read the bitmap from block
byte bytes new byte;
bfile.readBlock bytes;
bitmap new BitMapbytes;
rowsperblock schemagetTupleSizeInBytes;
indexes new Indexschemasize;
@Override
public void close
if bfileisOpen
write the bitmap
bfile.writeBlock bitmap.getBytes;
bfile.close;
@Override
public Iterator iterator
return new TupleIterator;
public class TupleIterator implements Iterator
private int rowno ;
private int currentblockno ;
private ByteBuffer buffer ByteBuffer.wrapnew byte;
@Override
public boolean hasNext
for rownorowno; rowno; rowno
if bitmapgetBitrowno
return true;
return false;
@Override
public Tuple next
read row
int blockno rownorowsperblock ;
int offset rownorowsperblock schema.getTupleSizeInBytes;
read the block
if currentblockno blockno
read the block
bfile.readBlockblockno buffer;
currentblockno blockno;
get the tuple
buffer.positionoffset;
Tuple t Tuple.deserializeschema buffer;
return t;
private int getRowNo
return rowno;
@Override
public Schema getSchema
return schema;
return the number of rows in table
@Override
public int size
int size;
for int i; i
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
