public class HashTable<K,V> {
    private RW rw;
    private List2<K,V> [] a;
    private int n;
    public HashTable (int n) {
	rw = new RW();
	a  = new List2[n];
	this.n = n;
    }
    public V lookup(K key) throws 
	          	   InterruptedException {
	rw.startRead();
	int i = Math.abs(key.hashCode())%n;
	V result = (a[i] == null) ? null :
				    a[i].lookup(key);
	synchronized (rw) {
	    rw.endRead();
	    return result;
	}
    }
    public void update(K key, V value) throws 
                            InterruptedException {
        rw.startWrite();
        int i = Math.abs(key.hashCode()) % n;
        if (a[i] == null)
             a[i] = new List2<K,V> (key,value,null);
        else 
             a[i].update(key,value);
        rw.endWrite();
    }
}    
