TIntDoubleMap classSums = new TIntDoubleHashMap();
for (WeightedEdge e : edges) {
int n = (e.to() == v) ? e.from() : e.to();
int nClass = vertexAssignments[n];
double weight = e.weight();
if (classSums.containsKey(nClass)) {
double curWeight = classSums.get(nClass);
classSums.put(nClass, weight + curWeight);
}
else {
classSums.put(nClass, weight);