One use of a hash table is to implement a set data type. You will implement the methods addElement, find, toString, resize, and the MySetIterator inner class in the class MySet. MySet uses a separate chaining hash table to implement a set of integers. To get started, import the starter file, MySet.java into the hashset package you create in a new Java Project. Please do not change any of the method signatures in either class. Implement the methods described below. You are free to test your code however you prefer. private void resize() This method "doubles" the table size and reinserts the values stored in the current table. The table size should remain prime. private boolean find(Integer e) This method returns true if the integer e is in the set and false otherwise. And below is method signature class: package hashset; import java.util.Iterator; public class MySet { // implements a set using a separate chaining hash table private class Node { private Integer element; private Node next; private Node(Integer e, Node n) { element = e; next = n; } } private Node table[]; //an array of linked list private int tableSize; //current number of lists in the table private int numElements; //number of elements in the set private final int primes[] = {7, 23, 59, 131, 271, 563, 1171, 2083, 4441, 8839, 16319, 32467, 65701, 131413, 263983, 528991}; private int primeIndex; //last prime used private int nextPrime(int p) { //finds the next prime from the list above //used for resizing and the initial size while (primes[primeIndex] <= p) primeIndex++; return primes[primeIndex]; } public MySet(int s) { //s is a hint for the initial size primeIndex = 0; tableSize = nextPrime(s); table = new Node[tableSize]; numElements = 0; } //return the hash function value for k private int hash(Integer k) { return Math.abs(k.hashCode() % tableSize); } //"double" the table size and reinsert the values stored in the //current table. the table size should remain prime private void resize() { } //returns true when e is in the set, otherwise returns false public boolean find(Integer e) { return false; } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

One use of a hash table is to implement a set data type. You will implement the methods addElement, find, toString, resize, and the MySetIterator inner class in the class MySet. MySet uses a separate chaining hash table to implement a set of integers. To get started, import the starter file, MySet.java into the hashset package you create in a new Java Project. Please do not change any of the method signatures in either class. Implement the methods described below. You are free to test your code however you prefer.


private void resize()
This method "doubles" the table size and reinserts the values stored in the current table. The table size should remain prime.


private boolean find(Integer e)
This method returns true if the integer e is in the set and false otherwise.

And below is method signature class:

package hashset;

import java.util.Iterator;

public class MySet {
    // implements a set using a separate chaining hash table

    private class Node {
        private Integer element;
        private Node next;
        private Node(Integer e, Node n) {
            element = e;
            next = n;
        }
    }

    private Node table[]; //an array of linked list
    private int tableSize; //current number of lists in the table
    private int numElements; //number of elements in the set

    private final int primes[] = {7, 23, 59, 131, 271, 563, 1171,
            2083, 4441, 8839, 16319, 32467,
            65701, 131413, 263983, 528991};
    private int primeIndex; //last prime used

    private int nextPrime(int p) {
        //finds the next prime from the list above
        //used for resizing and the initial size
        while (primes[primeIndex] <= p)
            primeIndex++;
        return primes[primeIndex];
    }
    public MySet(int s) {
        //s is a hint for the initial size
        primeIndex = 0;
        tableSize = nextPrime(s);
        table = new Node[tableSize];
        numElements = 0;
    }
    
    //return the hash function value for k
    private int hash(Integer k) {
        
        return Math.abs(k.hashCode() % tableSize);
    }

    //"double" the table size and reinsert the values stored in the
    //current table. the table size should remain prime
    private void resize() {

 

    }

 

    //returns true when e is in the set, otherwise returns false
    public boolean find(Integer e) {
        return false;

    }

}

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Math class and its different methods
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education