Breadth First
Module: terminaltexteffects.utils.spanningtree.algo.breadthfirst
Breadth-first traversal over an already linked character graph.
This module provides the BreadthFirst traversal helper. It performs a
breadth-first walk over existing EffectCharacter.links relationships
instead of generating a new spanning tree.
BreadthFirst
Bases: SpanningTreeGenerator
Breadth-first traversal helper.
Uses breadth-first traversal to explore an already linked graph of
EffectCharacter nodes.
Attributes:
| Name | Type | Description |
|---|---|---|
starting_char |
EffectCharacter
|
Character where the traversal begins. |
explored_last_step |
list[EffectCharacter]
|
Characters newly discovered during the most recent step. |
char_explore_order |
list[EffectCharacter]
|
Characters in the order they were first discovered by the traversal. |
complete |
bool
|
Whether the algorithm is complete. |
Source code in terminaltexteffects/utils/spanningtree/algo/breadthfirst.py
__init__(terminal, starting_char=None, *, limit_to_text_boundary=False)
Initialize the algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
terminal
|
Terminal
|
TTE Terminal. |
required |
starting_char
|
EffectCharacter | None
|
Starting character for the
traversal. When |
None
|
limit_to_text_boundary
|
bool
|
If True, the starting character, if not provided, will be chosen within the text boundary. This should be True if the spanning tree was generated with limit_to_text_boundary=True. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
Unable to find a starting character. |
Source code in terminaltexteffects/utils/spanningtree/algo/breadthfirst.py
step()
Advance the traversal by one breadth-first layer.
Each step consumes the current frontier, records any newly discovered linked neighbors, and stores those newly discovered characters as the next frontier.
Note
complete becomes True only when _frontier is already empty at
the start of a call.