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
31 lines (24 sloc) 596 Bytes
package kb.howtokb.utils;
import gnu.trove.TIntFloatHashMap;
public class AdjacencyBackedSparseMatrix {
TIntFloatHashMap[] matrix;
float threshold;
public AdjacencyBackedSparseMatrix(float thres, int n) {
matrix = new TIntFloatHashMap[n];
for (int i=0; i<n; i++)
matrix[i] = new TIntFloatHashMap();
this.threshold = thres;
}
public void set(int x, int y, float value) {
if (value < threshold)
return;
matrix[x].put(y, value);
}
//upper triangle matrix
public float get(int x, int y) {
if (x <= y){
return matrix[x].get(y);
}
return matrix[y].get(x);
}
}