Skip to content

Commit c35e622

Browse files
committed
fix bugs
1 parent 3136599 commit c35e622

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

cyaron/graph.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from .utils import *
22
import random
3-
from typing import TypeVar, Callable
3+
from typing import TypeVar, Callable, List
44

55

66
class Edge:
@@ -54,16 +54,15 @@ def edge_count(self):
5454
return cnt
5555

5656
def to_matrix(self, **kwargs):
57-
"""to_matrix(self, **kwargs) -> list[list[Any]]
57+
"""to_matrix(self, **kwargs) -> GraphMatrix
5858
Convert the graph to adjacency matrix.
5959
**kwargs(Keyword args):
6060
int default = -1 -> the default value when the edge does not exist.
6161
Any merge(Any, Edge)
6262
= lambda val, edge: edge.weight
6363
-> the mapping from the old values in matrix and the edges to the new values in matrix.
64-
Note that the index start from 0 and the values in the Column 0 or the Row 0 are always the default.
6564
"""
66-
return GraphMatrix(self)
65+
return GraphMatrix(self, **kwargs)
6766

6867
def to_str(self, **kwargs):
6968
"""to_str(self, **kwargs) -> str
@@ -551,4 +550,10 @@ def __init__(self,
551550
self.matrix[edge.start][edge.end], edge)
552551

553552
def __str__(self):
554-
return '\n'.join([' '.join(map(str, row)) for row in self.matrix])
553+
return '\n'.join([' '.join(map(str, row[1:])) for row in self.matrix[1:]])
554+
555+
def __call__(self, u: int, v: int):
556+
return self.matrix[u][v]
557+
558+
def __iter__(self):
559+
return self.matrix.__iter__()

0 commit comments

Comments
 (0)