dist.edu.umd.hooka.Int2FloatMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cloud9 Show documentation
Show all versions of cloud9 Show documentation
University of Maryland's Hadoop Library
package edu.umd.hooka;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.apache.hadoop.io.FloatWritable;
import edu.umd.hooka.alignment.IndexedFloatArray;
public final class Int2FloatMap {
//TODO the performance of this class can be improved
TreeMap data = new TreeMap();
public Int2FloatMap() {}
public final void increment(int k, float delta) {
FloatWritable cvF = data.get(k);
cvF.set(cvF.get() + delta);
}
public final Set> entrySet() {
return data.entrySet();
}
public final int maxKey() {
return data.lastKey();
}
public final void createIfMissing(int k) {
Integer ki = new Integer(k);
if (data.get(ki) == null) {
FloatWritable n = new FloatWritable();
data.put(k, n);
}
}
public final void set(int k, float value) {
data.get(k).set(value);
}
public final float get(int k) {
return data.get(k).get();
}
public final FloatWritable getFloatWritable(int k) {
return data.get(k);
}
public IndexedFloatArray getAsIndexedFloatArray() {
int[] indices = new int[data.size()];
float[] values = new float[data.size()];
int c = 0;
for (Map.Entry p : data.entrySet()) {
indices[c] = p.getKey();
values[c] = p.getValue().get();
c++;
}
return new IndexedFloatArray(indices, values);
}
}