Skip to content

Commit

Permalink
feat(ir): add graph delegate and iterators
Browse files Browse the repository at this point in the history
This data structure and its iterators shall reduce complexity
for more advanced graph data structures. It manages nodes/edges
and we can implement different traversals etc. for it.
More advanced graphs can then delegate these operations to the
easier to test delegate.
  • Loading branch information
glencoe committed Nov 6, 2024
1 parent 868a188 commit 1cd2a35
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
HashableT = TypeVar("HashableT", bound=Hashable)


class HumbleBaseGraph(Generic[HashableT]):
class GraphDelegate(Generic[HashableT]):
def __init__(self) -> None:
"""We keep successor and predecessor nodes just to allow for easier implementation.
Currently, this implementation is not optimized for performance.
Expand All @@ -14,7 +14,7 @@ def __init__(self) -> None:

@staticmethod
def from_dict(d: dict[HashableT, Iterable[HashableT]]):
g = HumbleBaseGraph()
g = GraphDelegate()
for node, successors in d.items():
for s in successors:
g.add_edge(node, s)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from .graph_delegate import GraphDelegate
from .graph_iterators import bfs_iter_up, dfs_pre_order
from .humble_base_graph import HumbleBaseGraph


def test_iterating_breadth_first_upwards():
g = HumbleBaseGraph()
g = GraphDelegate()
"""
0
|
Expand All @@ -18,7 +18,7 @@ def test_iterating_breadth_first_upwards():
|/----+
5
"""
g = HumbleBaseGraph.from_dict(
g = GraphDelegate.from_dict(
{
"0": ["1", "2"],
"1": ["3"],
Expand All @@ -37,7 +37,7 @@ def test_iterating_breadth_first_upwards():


def test_iterating_depth_first_preorder():
g = HumbleBaseGraph()
g = GraphDelegate()
"""
0
|
Expand All @@ -52,7 +52,7 @@ def test_iterating_depth_first_preorder():
|/----+
5
"""
g = HumbleBaseGraph.from_dict(
g = GraphDelegate.from_dict(
{
"0": ["1", "2"],
"1": ["3"],
Expand Down

0 comments on commit 1cd2a35

Please sign in to comment.