Skip to content

Commit

Permalink
Merge pull request #48 from datavis-tech/optimize-has-edge
Browse files Browse the repository at this point in the history
Optimize hasEdge
  • Loading branch information
curran authored May 24, 2021
2 parents 400598c + 4ce2273 commit 01a6fa0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 18 deletions.
10 changes: 1 addition & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,7 @@ function Graph(serialized) {
}
// Returns true if there is an edge from node u to node v.
function hasEdge(u, v) {
var has = false;
if (edges[u]) {
adjacent(u).forEach(function (_v) {
if (_v === v) {
has = true;
}
});
}
return has;
return adjacent(u).includes(v);
}
// Computes the indegree for the given node.
// Not very efficient, costs O(E) where E = number of edges.
Expand Down
10 changes: 1 addition & 9 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,7 @@ function Graph(serialized?: Serialized) {

// Returns true if there is an edge from node u to node v.
function hasEdge(u: NodeId, v: NodeId) {
let has = false;
if (edges[u]) {
adjacent(u).forEach(function(_v) {
if(_v === v){
has = true;
}
});
}
return has;
return adjacent(u).includes(v);
}

// Computes the indegree for the given node.
Expand Down

0 comments on commit 01a6fa0

Please sign in to comment.