Skip to content

Commit

Permalink
bgraph: avoid adding duplicated edges in addEdge(src, dst)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzjjzzgggg committed Apr 9, 2020
1 parent dcf3074 commit 1b8ef88
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions graph/bgraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,12 @@ class BGraph {
* Add edge and keep neighbors in ordered vector.
*/
void addEdge(const int src, const int dst) {
addNodeL(src);
nodes_L_[src].addNbr(dst);
addNodeR(dst);
nodes_R_[dst].addNbr(src);
if (!isEdge(src, dst)) {
addNodeL(src);
nodes_L_[src].addNbr(dst);
addNodeR(dst);
nodes_R_[dst].addNbr(src);
}
}

/**
Expand Down Expand Up @@ -170,6 +172,6 @@ class BGraph {

}; /* BGraph */

} /* namespace graph */
} // namespace graph::bi

#endif /* __BGRAPH_H__ */

0 comments on commit 1b8ef88

Please sign in to comment.