-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathHashTable.java
More file actions
37 lines (30 loc) · 991 Bytes
/
HashTable.java
File metadata and controls
37 lines (30 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.util.LinkedList;
public class HashTable {
public static final int ARR_SIZE = 8;
public LinkedList<Bucket>[] arr = new LinkedList[ARR_SIZE];
//hash function
public int getIndexBelowMaxForKey(String str, int max) {
int hash = 0;
for (int i = 0; i < str.length(); i++) {
hash = (hash << 5) + hash + str.charAt(i);
hash = hash & hash; // Convert to 32bit integer
hash = Math.abs(hash);
}
return hash % max;
}
public static class Bucket {
//your code is here
}
public void insert (String key, String value) {
//your code is here
int index = getIndexBelowMaxForKey(key, ARR_SIZE);
}
public String retrieve(String key) {
// your code is here
int index = getIndexBelowMaxForKey(key, ARR_SIZE);
}
public void remove (String key) {
//your code is here
int index = getIndexBelowMaxForKey(key, ARR_SIZE);
}
}