Question: Hashing Implementation Objectives Helping you to understand hashing algorithms Implement hashing functions and an associative data structure The hash table for this assignment has two
Hashing Implementation
Objectives
Helping you to understand hashing algorithms
Implement hashing functions and an associative data structure
The hash table for this assignment has two distinct parts:
A set of hashing functions that compute a hash code from a string.
A data structure that uses the hashing functions to insert, remove, and search.
I need help in implementing these functions using lambda expressions, inner class, and an anonymous inner class
@FunctionalInterface
interface HashFunction {
int hash(String key);
}
public class Hasher {
// Hashing algorithms, see specification
/**
* Hashing algorithms, see provided documentation in assignment
* @param hashFunction FIRST, SUM, PRIME, OR JAVA
* @return the corresponding HashFunction
*/
public static HashFunction make(String hashFunction) {
switch (hashFunction) {
case "FIRST":
// YOUR CODE HERE
return null;
case "SUM":
// YOUR CODE HERE
return null;
case "PRIME":
// YOUR CODE HERE
return null;
case "JAVA":
// YOUR CODE HERE
return null;
default:
usage();
}
return null;
}
// Usage message
private static void usage() {
System.err.println("Usage: java Hasher
System.exit(1);
}
// Test code for hasher
public static void main(String[] args) {
args = Debug.init(args);
if (args.length != 2)
usage();
HashFunction sh = make(args[0]);
int hashCode = sh != null ? sh.hash(args[1]) : 0;
System.out.printf("'%s' hashes to %d using %s ", args[1], hashCode, args[0]);
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
