
public class HashTable implements Table {

	
	class Bucket {
		String key;
		int data;
		public Bucket(String k, int d) {
			key = k;
			data = d;
		}
	}
	
	final static int initSize = 4;
	
	Bucket buckets[];
	
	public HashTable() {
	   buckets = new Bucket[initSize];
	   for (int i = 0; i < buckets.length; i++) {
		  buckets[i] = null;
	   }
	}
	
	
	static int hash(String k) {
		int sum = 0;
		for (int i = 0; i < k.length(); i++) {
		   sum += k.charAt(i);	
		}
		return sum;
		
	}
	
	@Override
	public Integer get(String key) {
		int initpos =  hash(key) % buckets.length;
		int pos = initpos;
		
		do {
		    if (buckets[pos] == null) return null;
		    if (buckets[pos].key.equals(key)) return buckets[pos].data;
		    pos = (pos + 1)  % buckets.length;
		} while (pos != initpos);
		return null;
	}

	@Override
	public Table put(String key, Integer value) {
		int initpos =  hash(key) % buckets.length;
		int pos = initpos;
		
		do {
		    if (buckets[pos] == null || buckets[pos].key.equals(key)) {
		    	buckets[pos] = new Bucket(key,value);
		    	return this;
		    }
		    pos = (pos + 1)  % buckets.length;
		} while (pos != initpos);
		return null;
	}

	@Override
	public String show() {
		// TODO Auto-generated method stub
		return null;
	}

}

