package org.spbu.bdd.core;

public class Cache<V> {
	Object[] karr;
	V[] varr;
	
	public Cache(int capacity) {
		karr = new Object[capacity];
		varr = (V[])new Object[capacity];
	}
	
	public boolean contains(Object k) {
		return (k.equals(karr[idx(k)]));
	}
	
	public V get(Object k) {
		return varr[idx(k)];
	}
	
	public void put(Object k, V v) {
		int id=idx(k);
		karr[id] = k;
		varr[id] = v;
	}
	
	private int idx(Object o) {
		//int res = ((!o.getClass().isArray()) ? o.hashCode() : Arrays.deepHashCode((Object[])o)) % karr.length;
		int res = o.hashCode() % karr.length;
		if (res <0) res += karr.length;
		return res;
	}
}
