Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following private fields: 1 A one - dimensional array of rows, which is the table array. 2 A string for the name, which is

The following private fields:
1 A one-dimensional array of rows, which is the table array.
2 A string for the name, which is the name of the table itself.
3 A list of strings for the columns, which are the ordered names of the columns, including the key and the list of fields.
4 An integer for the degree, which is the number of columns, including the key and the list of fields.
5 An integer for the size, which is the current number of rows in the table.
6 An integer for the capacity, which is the maximum number of rows in the table and is always an odd prime number.
7 An integer for the fingerprint, which is the amortized sum of the hash codes of all rows in the array.
8 A static constant integer for the initial capacity, initialized to an odd prime number between 500 and 1000.
B A 2-ary constructor which takes a name parameter (string) and a columns parameter (list of strings).
1 Initialize the name field using the corresponding parameter.
2 Initialize the columns field using an immutable copy of the corresponding parameter.
3 Initialize the degree field based on the quantity of columns.
4 Call the clear method.
C A public clear method.
1 Initialize the capacity field to the initial capacity constant.
2 Initialize the array field with a length equal to the capacity.
3 Initialize the size field to 0.
4 Initialize the fingerprint to 0.
D Public methods for the following properties:
1 The degree, size, capacity, name, and columns methods which return the corresponding fields.
2 The hashCode method which returns the fingerprint.
3 The equals method which takes an object parameter.
i If the parameter is a table of any type (not just a hash table) and has the same fingerprint as this table, return true.
ii Otherwise, return false to indicate the parameter is unequal to this table.
E A private hashFunction method which takes a key parameter (string).
1 Define a salt which is a string literal containing your full name, then concatenate the salt with the given key.
2 Compute a hash code from the salted key above using a non-cryptographic hash function.
i Either translate a published algorithm from pseudocode or design your own algorithm.
ii Use either a polynomial rolling hash function or a noteworthy non-cryptographic hash function.
3 Return that hash code modulo the capacity as an index, using the floor modulus instead of the modulus operator.
2ND QUARTER: PUT, GET, LINEAR PROBING
F A public put method which takes a key parameter (string), then a list of fields parameter (list of objects).
1 If the degree of the given row doesnt match the degree field of the table, throw an illegal argument exception.
2 Create a new row composed of the key parameter and an unmodifiable view of the list of fields parameter.
3 Use your hash function and linear probing to find an old row with the given key.
4 On a miss, set the new row at the probed index, increase the size by 1, update the fingerprint, then return null.
5 On a hit, replace the old row at the probed index with the new row, update the fingerprint, then return the old list of fields.
6 On an unexpected fall-through when linear probing because the array is full, throw an illegal state exception.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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