package yi.ds.sum;

import java.util.HashMap;

/**
 * IndexedSummationHashMap implements a hash of integer summuation structures.
 * The key is a integer (index).  When you want to add a set of data according
 * to their index, then you can use this structure.
 */
public class IndexedIntSummationHashMap extends HashMap{
  public void putToSum(int index, int value) {
    Integer key = new Integer(index);

    // if the index is not in the hash yet
    if (!containsKey(key)) {
      put(key, new IntSummationStruct());
    }

    // add to the corresponding summation struct
    IntSummationStruct sum = (IntSummationStruct)get(key);
    sum.putToSum(value);
  }

  public IntSummationStruct getIntSummationStruct(int index) {
    return (IntSummationStruct)get(new Integer(index));
  }

}