package yi.stat.hist;

import java.util.*;

/**
 * HashBasedHist implements a hash based histogram which is suitable for sparse
 * histogram
 */
public class ObjectCounter extends HashMap{
  /**
   * How many data has been put into the histogram
   */
  int m_total = 0;

  public void put(Object o) {
    put(o, 1);
  }

  public void put(Object o, int times) {
    int count = getCount(o);
    put(o, new Integer(count + times));

    m_total += times;
  }

  public int getTotal() {
    return m_total;
  }

  public int getCount(Object key) {
    return containsKey(key)? ((Integer)get(key)).intValue() : 0;
  }
}