Skip to content

Commit 01a6fa0

Browse files
authored
Merge pull request #48 from datavis-tech/optimize-has-edge
Optimize hasEdge
2 parents 400598c + 4ce2273 commit 01a6fa0

2 files changed

Lines changed: 2 additions & 18 deletions

File tree

index.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,7 @@ function Graph(serialized) {
137137
}
138138
// Returns true if there is an edge from node u to node v.
139139
function hasEdge(u, v) {
140-
var has = false;
141-
if (edges[u]) {
142-
adjacent(u).forEach(function (_v) {
143-
if (_v === v) {
144-
has = true;
145-
}
146-
});
147-
}
148-
return has;
140+
return adjacent(u).includes(v);
149141
}
150142
// Computes the indegree for the given node.
151143
// Not very efficient, costs O(E) where E = number of edges.

index.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,7 @@ function Graph(serialized?: Serialized) {
146146

147147
// Returns true if there is an edge from node u to node v.
148148
function hasEdge(u: NodeId, v: NodeId) {
149-
let has = false;
150-
if (edges[u]) {
151-
adjacent(u).forEach(function(_v) {
152-
if(_v === v){
153-
has = true;
154-
}
155-
});
156-
}
157-
return has;
149+
return adjacent(u).includes(v);
158150
}
159151

160152
// Computes the indegree for the given node.

0 commit comments

Comments
 (0)