Treelib: generátor a funkce na hledání následujících nodů
This commit is contained in:
parent
8071cc2554
commit
78a667b42c
1 changed files with 28 additions and 5 deletions
|
@ -107,6 +107,12 @@ def all_children(node):
|
|||
yield br
|
||||
|
||||
# Generátor následníků v "the-right-order"
|
||||
# Bez tohoto vrcholu
|
||||
def all_following(node):
|
||||
current = general_next(node)
|
||||
while current is not None:
|
||||
yield current
|
||||
current = general_next(current)
|
||||
|
||||
## Filtrační hledání
|
||||
# Najdi dalšího bratra nějakého typu, nebo None.
|
||||
|
@ -115,15 +121,32 @@ def get_next_brother_of_type(node, type):
|
|||
for current in right_brothers(node):
|
||||
if isinstance(current, type):
|
||||
return current
|
||||
return None
|
||||
|
||||
def get_prev_brother_of_type(node, type):
|
||||
pass
|
||||
# Na tohle není rozumný generátor, ani ho asi nechceme, prostě to implementujeme cyklem.
|
||||
current = node
|
||||
while safe_pred(current) is not None:
|
||||
current = safe_pred(current)
|
||||
if isinstance(current, type):
|
||||
return current
|
||||
return None
|
||||
|
||||
# Totéž pro "the-right-order" pořadí
|
||||
def get_next_node_of_type(current, type):
|
||||
pass
|
||||
def get_next_node_of_type(current, type):
|
||||
pass
|
||||
def get_next_node_of_type(node, type):
|
||||
for cur in all_folowing(node):
|
||||
if isinstance(cur, type):
|
||||
return cur
|
||||
return None
|
||||
|
||||
def get_prev_node_of_type(node, type):
|
||||
# Na tohle není rozumný generátor, ani ho asi nechceme, prostě to implementujeme cyklem.
|
||||
current = node
|
||||
while general_prev(current) is not None:
|
||||
current = general_prev(current)
|
||||
if isinstance(current, type):
|
||||
return current
|
||||
return None
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue