Skip to content

Commit d4d6a44

Browse files
committed
Add doc composed graph
1 parent 6b5b05b commit d4d6a44

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* ~~Add doc about node / graph creation~~
2525
* ~~Add documentation about graph nodes~~
2626
* ~~Add documentation about custom hook~~
27+
* ~~Add documentation Composed Visitor~~
2728

2829
## Feature todo
2930

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,41 @@ class MyCustomVisitor(AbstractVisitor):
349349
...
350350
```
351351

352+
### Composed Visitor
353+
354+
Usually, in order to complete the action you want to perform on a graph, you require to chain the visitor one after the other. In order to do so, a utility exist in freexgraph called VisitorComposer.
355+
356+
A visitor composer is split between three part :
357+
* before : a list of visitor pattern to apply one after the other. Each of those visitations will trigger a traversal of the graph. All those visitors are launched in order before the action
358+
* action : a list of visitor pattern to apply in one traversal. It is useful in order to not traverse the graph too many times if not required
359+
* after : a list of visitor pattern to apply one after the other. Each of those visitations will trigger a traversal of the graph. All those visitors are launched in order after the action
360+
361+
The action visitor list from the visitor composer is what is special. It makes it possible to do multiple actions in one traversal of the graph.
362+
363+
Usage example:
364+
```python
365+
all_before: List[AbstractVisitor] = [ VisitorA(), VisitorB() ]
366+
actions: List[AbstractVisitor] = [ VisitorC(), VisitorD(), VisitorE() ]
367+
all_after: List[AbstractVisitor] = [ VisitorF(), VisitorG() ]
368+
369+
visitor_composed = VisitorComposer(before=all_before, action=actions, after=all_after)
370+
371+
# At visitation of the composed visitor
372+
# * VisitorA is applied on execution_graph.root (full traversal)
373+
# * VisitorB is applied on execution_graph.root (full traversal)
374+
#
375+
# In one traversal
376+
# * VisitorC action is applied on each node
377+
# * VisitorD action is applied on each node
378+
# * VisitorE action is applied on each node
379+
#
380+
# * VisitorF is applied on execution_graph.root (full traversal)
381+
# * VisitorG is applied on execution_graph.root (full traversal)
382+
visitor_composed.visit(execution_graph.root)
383+
```
384+
352385
### Reverse visit
386+
353387
It is possible to revert the order of visitation of any visitor by setting its attribute `is_reversed` of the visitor (works with any type of visitor inheriting from AbstractVisitor).
354388
example :
355389
```python

0 commit comments

Comments
 (0)