Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with edge_index #13

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/jLouvain.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
Author: Corneliu S. (github.com/upphiminn)

This is a javascript implementation of the Louvain
Expand Down Expand Up @@ -83,11 +83,12 @@ function get_graph_size(graph) {
function add_edge_to_graph(graph, edge) {
update_assoc_mat(graph, edge);

if (edge_index[edge.source + '_' + edge.target]) {
graph.edges[edge_index[edge.source + '_' + edge.target]].weight = edge.weight;
let key = edge.source + '_' + edge.target;
if (edge_index.hasOwnProperty(key)) {
graph.edges[edge_index[key]].weight = edge.weight;
} else {
edge_index[key] = graph.edges.length;
graph.edges.push(edge);
edge_index[edge.source + '_' + edge.target] = graph.edges.length - 1;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand why you think this is wrong? Indexes shouldn't go up to length; otherwise the other changes look fine :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this logic is not wrong at all. It's just that subtracting 1 seemed a bit redundant since we can get the same value from graph.edges.length prior to adding the edge to graph.edges.

}
}

Expand Down