class LossyCounting implements HeavyHitter, Serializable {

	public void merge(HeavyHitter toMerge) throws HeavyHitterMergeException {
		try{
			LossyCounting lsToMerge = (LossyCounting)toMerge;
			if (this.fraction!=lsToMerge.fraction){
				throw new HeavyHitterMergeException("Both heavy hitter structures must be identical");
			}
			this.cardinality+=lsToMerge.cardinality;
			this.bucket = (long)Math.floor(cardinality*error);
			for (Map.Entry<Object, Counter> entry : lsToMerge.heavyHitters.entrySet()){
				Counter counter = this.heavyHitters.get(entry.getKey());
				if (counter==null){
					this.heavyHitters.put(entry.getKey(),entry.getValue());
				}else{
					Counter mergingCounter = entry.getValue();
					this.heavyHitters.put(entry.getKey(),
							new Counter(mergingCounter.lowerBound+counter.lowerBound, mergingCounter.frequencyError +counter.frequencyError));
				}
			}
			updateHeavyHitters();
		}catch (ClassCastException ex){
			throw new HeavyHitterMergeException("Both heavy hitter structures must be identical");
		}
	}

	public  LossyCounting(double fraction, double error);

}