private int N, M;
private SeqST<Key, Value>[] st;
public HashST(int M) {
this.M = M;
st = (SeqST<Key, Value>[])new seqST[M];
for(int i = 0; i < M; i++) st[i] = new SeqRT();
}
private int hash(Key key) {
//what is missing here?
}
public Value get(Key key) {
return (Value)st[hash(key)].get(key);
}
public void put(Key key, Value val) {
st[hash(key)].put(key, val);
}
private class SeqST<Key, Value> {
private Node first;
private class Node {
Key key;
Value val;
Node next;
public Node(Key key, Value val, Node next) {
this.key = key;
this.val = val;
this.next = next;
}
}
public boolean isEmpty() {return first == null;}
public Value get(Key key) {
for(Node x = first; x != null; x = x.next) {
if(x.key.equals(key)) return x.val;
}
return null;
}
public void put(Key key, Value val) {
for(Node x = first; x != null; x = x.next) {
if(x.key.equals(key)) {
x.val = val;
return;
}
}
first = new Node(key, val, null);
}
}
}