org.heigit.bigspatialdata.oshdb.api.mapreducer.MutableWeightedDouble Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of oshdb-api Show documentation
Show all versions of oshdb-api Show documentation
API to query the OpenStreetMap History Database. Includes MapReduce functionality to filter, analyze and aggregate data.
package org.heigit.bigspatialdata.oshdb.api.mapreducer;
import java.io.Serializable;
import org.heigit.bigspatialdata.oshdb.api.generic.WeightedValue;
/**
* Mutable version of WeightedValue type.
*
* For internal use to do faster aggregation during reduce operations.
*/
class MutableWeightedDouble implements Serializable {
double num;
double weight;
private MutableWeightedDouble(double num, double weight) {
this.num = num;
this.weight = weight;
}
static MutableWeightedDouble identitySupplier() {
return new MutableWeightedDouble(0.0, 0.0);
}
static MutableWeightedDouble accumulator(
MutableWeightedDouble acc,
WeightedValue cur) {
acc.num = acc.num + cur.getValue().doubleValue() * cur.getWeight();
acc.weight += cur.getWeight();
return acc;
}
static MutableWeightedDouble combiner(
MutableWeightedDouble a,
MutableWeightedDouble b) {
return new MutableWeightedDouble(a.num + b.num, a.weight + b.weight);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy