Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A public remove method which takes a key parameter. 1 Find the path of the digest of the key equal to the given object (

A public remove method which takes a key parameter.
1 Find the path of the digest of the key equal to the given object (calling steps K and L in order).
2 Check if a file exists at the path of the digest to determine a hit or a miss.
3 On a hit, readRow from the path of the old row, deleteRow at the same path, writeInt to the size and fingerprint
paths under the metadata directory to update them (like in previous modules), and return the old list of fields.
4 On a miss, return null.
R A public iterator method which returns an iterator of rows.
1 Walk the data directory by streaming as follows:
i Filter the stream to include only files which arent directories.
ii Map each path in the stream to the row stored there using readRow.
2 Return the iterator from the stream.
S A public toString method.
1 Return an unsorted view of the table by calling toTabularView.
page 3/5
3RD QUARTER: CUSTOM BYTE ENCODINGS
A' This quarter improves the efficiency of the table in a measurable way and can be enabled and disabled by a flag.
1 The 1
st and 2
nd quarters should pass 100% of the unit tests and be committed before starting this quarter.
2 The 1
st and 2
nd quarters write and read objects using the Serializable API, which is time and space inefficient.
3 The 3
rd quarter adopts custom byte encodings, which are time and space efficient.
B' Modify the following private fields:
1 A static constant boolean flag for whether the table should use custom byte encodings instead of serializable objects,
which should be initialized to true when this quarter is in use.
C' Modify the writeInt method.
1 If the custom byte encoding flag is true, allocate a byte buffer with a capacity which fits a 32-bit integer value, put the given
integer into it, convert it to a byte array, and write the corresponding bytes to the given path.
2 Otherwise, execute the original code from step E for serializable integers.
D' Modify the readInt method.
1 If the custom byte encoding flag is true, read all bytes from the given path, wrap the corresponding byte array within a
byte buffer, get the 32-bit integer value from the buffer, and return the integer.
2 Otherwise, execute the original code from step F for serializable integers.
E' In the Row record, modify the following features:
1 A public getBytes method which returns a byte array.
i Create a new list of objects which starts with the rows key and continues with each field of the rows list of fields.
ii Use a loop over the list to predict the total number of bytes needed to encode the list as a record.
iii Allocate a byte buffer with a capacity equal to the total number of bytes predicted.
iv For each object in the list, encode the corresponding record bytes and put them into the buffer.
v Return the byte array from the buffer.
2 A public static fromBytes method which takes a byte array parameter and returns a row.
i Create a new list of objects which is empty.
ii Wrap a byte buffer around the given byte array.
iii While the buffer has remaining record bytes, decode the corresponding objects and add them into the list.
iv Return a new row with the first object of the list as the key and the rest of the objects of the list as the row.
3 For steps 1 and 2 above, use the following custom byte encodings:
i Each field starts with a 1-byte tag (also called a descriptor).
ii For a string field, the tag stores the length of the string in character bytes (either zero or a positive number), and the
rest stores the corresponding character bytes (using the default UTF8 either explicitly or implicitly).
iii For an integer field, the tag stores a unique negative constant, and the rest stores the 32-bit value of the number.
iv For a floating point (double) field, the tag stores a unique negative constant, and the rest stores the 64-bit value of
the number.
v For a boolean field which is true, the tag stores a unique negative constant, and there is nothing more.
vi For a boolean field which is false, the tag stores a unique negative constant, and there is nothing more.
vii For a null field, the tag stores a unique negative constant, and there is nothing more.
F' Modify the writeRow method.
1 If the custom byte encoding flag is true, create a byte array from the given row by calling its getBytes method, and write
the corresponding bytes to the given path.
2 Otherwise, execute the original code from step H for serializable rows.
G' Modify the readRow method.
1 If the custom byte encoding flag is true, read all bytes from the given path, create a new row by calling the static
fromBytes method with the corresponding byte array, and return the new row.
2 Otherwise, execute the original code from step I for serializable rows.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

27 please thank you

Answered: 1 week ago

Question

Question 5) Let n = N and Y Answered: 1 week ago

Answered: 1 week ago