Permalink
Cannot retrieve contributors at this time
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?
HowToKB/src/kb/howtokb/utils/AdjacencyBackedSparseMatrix.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
31 lines (24 sloc)
596 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |