Skip to content

Commit 0d62fa5

Browse files
author
Roman Lishtaba
committed
adding alternative constructors for directed and undirected graphs
1 parent a852957 commit 0d62fa5

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,10 +503,10 @@ Any DAG has at least one topological ordering, and algorithms are known for cons
503503

504504
```python
505505

506-
from py_algorithms.graph import new_graph, topological_sort_f1
506+
from py_algorithms.graph import new_directed_graph, topological_sort_f1
507507

508508

509-
dag = new_graph(directed=True)
509+
dag = new_directed_graph()
510510
a = dag.insert_vertex('A')
511511
b = dag.insert_vertex('B')
512512
c = dag.insert_vertex('C')

py_algorithms/graph/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
__all__ = [
22
'Graph',
33
'Vertex',
4-
'new_graph'
5-
'topological_sort_f1'
4+
'directed_graph'
5+
'new_undirected_graph'
6+
'new_topological_sort_f1'
67
]
78

89
from typing import List, Callable
@@ -12,8 +13,12 @@
1213
from .topological_sort import TopologicalSort
1314

1415

15-
def new_graph(directed: bool = False) -> Graph:
16-
return Graph(directed)
16+
def new_directed_graph() -> Graph:
17+
return Graph(directed=True)
18+
19+
20+
def new_undirected_graph() -> Graph:
21+
return Graph(directed=False)
1722

1823

1924
def new_topological_sort() -> Callable[[Graph], List[Vertex]]:

tests/py_algorithms/graph/adt/graph_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from py_algorithms.graph import new_graph
1+
from py_algorithms.graph import new_undirected_graph
22

33

44
class TestGraphApi:
55
def test_graph_constructor(self):
6-
g = new_graph()
6+
g = new_undirected_graph()
77
v1 = g.insert_vertex("A")
88
v2 = g.insert_vertex("B")
99
v3 = g.insert_vertex("C")

tests/py_algorithms/graph/topological_sort_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from py_algorithms.graph import new_graph, topological_sort_f1
1+
from py_algorithms.graph import new_directed_graph, topological_sort_f1
22

33

44
class TestTopologicalSort:
55
def test_topological_sort(self):
6-
dag = new_graph(directed=True)
6+
dag = new_directed_graph()
77
a = dag.insert_vertex('A')
88
b = dag.insert_vertex('B')
99
c = dag.insert_vertex('C')

0 commit comments

Comments
 (0)