Skip to content

Commit 79b7a24

Browse files
Add method Graph.edge_count
1 parent fffe5f0 commit 79b7a24

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

cyaron/graph.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ def __init__(self, point_count, directed=False):
3939
"""
4040
self.directed = directed
4141
self.edges = [[] for i in range(point_count + 1)]
42+
43+
def edge_count(self):
44+
"""edge_count(self) -> int
45+
Return the count of the edges in the graph.
46+
"""
47+
cnt = sum(len(node) for node in self.edges)
48+
if not self.directed:
49+
cnt //= 2
50+
return cnt
4251

4352
def to_str(self, **kwargs):
4453
"""to_str(self, **kwargs) -> str

0 commit comments

Comments
 (0)