/**
* @author luxiangxing
* @time 2017-05-05
* @email xiangxingchina@163.com
* @tel 15330078427
*/
public class SimpleHashMap<K,V> {
private int size = 100;
private Entry<K,V>[] table = new Entry[size];
public void put(K k,V v){
int h = hash(k);
Entry o = table[h];
table[h] = new Entry(h,k,v,o);
}
public V get(K k){
int h = hash(k);
Entry<K,V> c = table[h];
while(c!=null){
if (c.k.equals(k)) {
return c.v;
}
c = c.e;
}
return null;
}
private int hash(K key) {
return (key.hashCode() & 0x7fffffff) % size;
}
}
class Entry<K,V>{
private int h;
K k;
V v;
Entry e;
public Entry(int h,K k,V v,Entry e) {
this.h = h;
this.k = k;
this.v = v;
this.e = e;
}
}