I have this class:
public class docInfo {
private int freq;
private HashMap<String, Double> m = new HashMap<String, Double>();
}
private Map<String, docInfo> m;
I want to iterate over all the docInfo’s Double value and change it:
docInfo documento;
for (Map.Entry<String, docInfo> entry : m.entrySet()) {
word = entry.getKey();
docs = entry.getValue(); // docs map
for (Map.Entry<String, Double> entry2 : docs.getM().entrySet()){
score = entry2.getValue();
temp = score;
double log = Math.log10(docs.getFreq());
double tfw = log+cons;
docs.changeScoreTo(entry2.getKey(), tfw);
//entry2.setValue(tfw);
}
}
It is working, the problem is, it is taking too long to run and i think my code is not the fittest for the job. Any help would be appreciated,
You really should use the profiler to understand why code is slow. It’s better than guessing. If I had to guess, though, I’d say the problem is the very large maps (27K) are slow to build and retrieve. The default hash tables are much too small for 27K entries and so you are doing a lot of rehashing as you assemble.
Try
And try a profiler to let us know which lines eat cycles.