@Override
    public double sim(int word1, int word2) {
        
        if (word1 > word2) {
            int temp = word1;
            word1 = word2;
            word2 = temp;
        } else if (word1 == word2) {
            return 1;
        }
        // Binary search
        int indStr = tListStr[word1],
            indEnd = tListEnd[word1],
            indMid = 0;
        while (indStr <= indEnd) {
        	indMid = (indStr + indEnd) / 2;
        	if (tListID[indMid] == word2) {
            	double triFreq = rt[indMid];
            	return sim.sim(freqs[word1], freqs[word2], (long)triFreq);
        	}
            else if (tListID[indMid] > word2)
                indEnd = indMid - 1;
            else
                indStr = indMid + 1;
        }
        return 0;
    }