test_class.declarator: LOG = LoggerFactory.getLogger(LossyCountingTest.class)
test_class.modifier: private static final
test_class.original_string: private static final Logger LOG = LoggerFactory.getLogger(LossyCountingTest.class);
test_class.type: Logger
test_class.var_name: LOG
test_class.declarator: fraction = 0.01
test_class.modifier: static final
test_class.original_string: static final double fraction = 0.01;
test_class.type: double
test_class.var_name: fraction
test_class.declarator: error = 0.005
test_class.modifier: static final
test_class.original_string: static final double error = 0.005;
test_class.type: double
test_class.var_name: error
test_class.declarator: r = new Random()
test_class.modifier: static final
test_class.original_string: static final Random r = new Random();
test_class.type: Random
test_class.var_name: r
test_class.declarator: cardinality = 1000000
test_class.modifier: static final
test_class.original_string: static final int cardinality = 1000000;
test_class.type: int
test_class.var_name: cardinality
test_class.declarator: maxScale = 100000
test_class.modifier: static final
test_class.original_string: static final int maxScale = 100000;
test_class.type: int
test_class.var_name: maxScale
test_class.file: flink-contrib/flink-operator-stats/src/test/java/org/apache/flink/contrib/operatorstatistics/heavyhitters/LossyCountingTest.java
test_class.identifier: LossyCountingTest
test_case.body: @Test
  	public void merge() throws HeavyHitterMergeException {
  		int numToMerge = 5;
  		LossyCounting merged = new LossyCounting(fraction,error);
  		LossyCounting[] sketches = new LossyCounting[numToMerge];
  
  		long[] actualFreq = new long[maxScale];
  		long totalCardinality = 0;
  
  		for (int i = 0; i < numToMerge; i++) {
  			sketches[i] = new LossyCounting(fraction,error);
  			for (int j = 0; j < cardinality; j++) {
  				int val;
  				if (r.nextDouble()<0.1){
  					val = r.nextInt(10);
  				}else{
  					val = r.nextInt(maxScale);
  				}
  				sketches[i].addObject(val);
  				actualFreq[val]++;
  				totalCardinality++;
  			}
  			merged.merge(sketches[i]);
  		}
  
  		System.out.println("\nMERGED\n" + merged.toString());
  
  		Map<Object,Long> mergedHeavyHitters = merged.getHeavyHitters();
  		long frequency = (long)(totalCardinality*fraction);
  		long minFrequency = (long)(totalCardinality*(fraction-error));
  
  		System.out.println("Frequency Threshold:" + frequency);
  		System.out.println("False positive Threshold:" + minFrequency);
  		System.out.println("Frequency of 14:" + actualFreq[14]);
  
  		System.out.println("Real frequent items: ");
  
  		for (int i = 0; i < actualFreq.length; ++i) {
  			if (actualFreq[i]>=frequency) {
  				System.out.println(i+": "+actualFreq[i]);
  				assertTrue("All items with freq. > s.n will be found. Item " + i + ". Real freq. " + actualFreq[i]+" Expected freq."+ frequency, mergedHeavyHitters.containsKey(i));
  			}
  			if (mergedHeavyHitters.containsKey(i)){
  				assertTrue("no item with freq. < (s-e).n will be found. Item " + i + ". Real freq. " + actualFreq[i]+" Min freq."+ minFrequency, actualFreq[i]>=minFrequency);
  				assertTrue("the estimated freq. underestimates the true freq. by < e.n. Real freq. " + actualFreq[i] + " Lower bound "+mergedHeavyHitters.get(i),
  						Math.abs(mergedHeavyHitters.get(i)-actualFreq[i]) < error*cardinality);
  			}
  		}
  
  	}
test_case.class_method_signature: LossyCountingTest.merge()
test_case.full_signature: @Test public void merge()
test_case.identifier: merge
test_case.invocations: nextDouble nextInt nextInt addObject merge println toString getHeavyHitters println println println println println assertTrue containsKey containsKey assertTrue assertTrue get abs get
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void merge()
focal_class.declarator: fraction
focal_class.modifier: private
focal_class.original_string: private double fraction;
focal_class.type: double
focal_class.var_name: fraction
focal_class.declarator: error
focal_class.modifier: private
focal_class.original_string: private double error;
focal_class.type: double
focal_class.var_name: error
focal_class.declarator: cardinality
focal_class.modifier: private
focal_class.original_string: private long cardinality;
focal_class.type: long
focal_class.var_name: cardinality
focal_class.declarator: heavyHitters
focal_class.modifier: private
focal_class.original_string: private Map<Object,Counter> heavyHitters;
focal_class.type: Map<Object,Counter>
focal_class.var_name: heavyHitters
focal_class.declarator: bucket
focal_class.modifier: private
focal_class.original_string: private long bucket;
focal_class.type: long
focal_class.var_name: bucket
focal_class.file: flink-contrib/flink-operator-stats/src/main/java/org/apache/flink/contrib/operatorstatistics/heavyhitters/LossyCounting.java
focal_class.identifier: LossyCounting
focal_class.interfaces: implements HeavyHitter, Serializable
focal_class.class_method_signature: LossyCounting.LossyCounting(double fraction, double error)
focal_class.full_signature: public  LossyCounting(double fraction, double error)
focal_class.identifier: LossyCounting
focal_class.modifiers: public
focal_class.parameters: (double fraction, double error)
focal_class.signature:  LossyCounting(double fraction, double error)
focal_class.class_method_signature: LossyCounting.addObject(Object o)
focal_class.full_signature: @Override public void addObject(Object o)
focal_class.identifier: addObject
focal_class.modifiers: @Override public
focal_class.parameters: (Object o)
focal_class.return: void
focal_class.signature: void addObject(Object o)
focal_class.class_method_signature: LossyCounting.updateHeavyHitters()
focal_class.full_signature: public void updateHeavyHitters()
focal_class.identifier: updateHeavyHitters
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void updateHeavyHitters()
focal_class.class_method_signature: LossyCounting.merge(HeavyHitter toMerge)
focal_class.full_signature: public void merge(HeavyHitter toMerge)
focal_class.identifier: merge
focal_class.modifiers: public
focal_class.parameters: (HeavyHitter toMerge)
focal_class.return: void
focal_class.signature: void merge(HeavyHitter toMerge)
focal_class.class_method_signature: LossyCounting.getHeavyHitters()
focal_class.full_signature: @Override public HashMap<Object,Long> getHeavyHitters()
focal_class.identifier: getHeavyHitters
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: HashMap<Object,Long>
focal_class.signature: HashMap<Object,Long> getHeavyHitters()
focal_class.class_method_signature: LossyCounting.toString()
focal_class.full_signature: @Override public String toString()
focal_class.identifier: toString
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String toString()
focal_method.body: 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");
  		}
  	}
focal_method.class_method_signature: LossyCounting.merge(HeavyHitter toMerge)
focal_method.full_signature: public void merge(HeavyHitter toMerge)
focal_method.identifier: merge
focal_method.invocations: floor entrySet get getKey put getKey getValue getValue put getKey updateHeavyHitters
focal_method.modifiers: public
focal_method.parameters: (HeavyHitter toMerge)
focal_method.return: void
focal_method.signature: void merge(HeavyHitter toMerge)