Skip to content
Permalink
0d82ff1dc4
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
34 lines (26 sloc) 723 Bytes
package kb.howtokb.utils;
import gnu.trove.TLongFloatHashMap;
public class SparseSimMatrix {
TLongFloatHashMap matrix;
float threshold;
public SparseSimMatrix(float thres) {
matrix = new TLongFloatHashMap();
this.threshold = thres;
}
public void set(int x, int y, float value) {
if (value < threshold)
return;
long key = intpairToLong(x, y);
matrix.put(key, value);
}
//Matrix is symmetric then only store the upper triangle part
public float get(int x, int y) {
if (x <=y )
return matrix.get(intpairToLong(x, y));
return matrix.get(intpairToLong(y, x));
}
private long intpairToLong(int l, int r) {
return ((long) l << 32) + r;
// return (long) (l << 32) | (r & 0XFFFFFFFFL);
}
}