All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dist.edu.umd.hooka.Int2FloatMap Maven / Gradle / Ivy

There is a newer version: 2.0.1
Show newest version
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);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy