Java Program to Implement Hash Tables with Double Hashing

This is a Java Program to implement hash tables with Double Hashing. A hash table (also hash map) is a data structure used to implement an associative array, a structure that can map keys to values. A hash table uses a hash function to compute an index into an array of buckets or slots, from which the correct value can be found. Double Hashing is a probe sequence in which the interval between probes is computed by another hash function.

Here is the source code of the Java program to implement hash tables with Double Hashing. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.

/*

* Java program to implement hash table with double hashing

*/

importjava.util.Scanner;

importjava.math.*;

/* Class LinkedHashEntry */

class HashEntry

{

String key;

int value;

/* Constructor */

HashEntry(String key, int value)

{

this.key= key;

this.value= value;

}

}

/* Class HashTable */

class HashTable

{

privateint TABLE_SIZE;

privateint size;

private HashEntry[] table;

privateint primeSize;

/* Constructor */

public HashTable(int ts)

{

size =0;

TABLE_SIZE = ts;

table =new HashEntry[TABLE_SIZE];

for(int i =0; i < TABLE_SIZE; i++)

table[i]=null;

primeSize = getPrime();

}

/* Function to get prime number less than table size for myhash2 function */