modm_data.utils.anytree
1# Copyright 2022, Niklas Hauser 2# SPDX-License-Identifier: MPL-2.0 3 4from anytree.iterators import AbstractIter 5 6 7class ReversePreOrderIter(AbstractIter): 8 @staticmethod 9 def _iter(children, filter_, stop, maxlevel): 10 for child_ in reversed(children): 11 if not AbstractIter._abort_at_level(2, maxlevel): 12 descendantmaxlevel = maxlevel - 1 if maxlevel else None 13 yield from ReversePreOrderIter._iter( 14 child_.children, filter_, stop, descendantmaxlevel) 15 if stop(child_): 16 continue 17 if filter_(child_): 18 yield child_
class
ReversePreOrderIter(anytree.iterators.abstractiter.AbstractIter):
8class ReversePreOrderIter(AbstractIter): 9 @staticmethod 10 def _iter(children, filter_, stop, maxlevel): 11 for child_ in reversed(children): 12 if not AbstractIter._abort_at_level(2, maxlevel): 13 descendantmaxlevel = maxlevel - 1 if maxlevel else None 14 yield from ReversePreOrderIter._iter( 15 child_.children, filter_, stop, descendantmaxlevel) 16 if stop(child_): 17 continue 18 if filter_(child_): 19 yield child_
Iterate over tree starting at node
.
Base class for all iterators.
Keyword Args:
filter_: function called with every node
as argument, node
is returned if True
.
stop: stop iteration at node
if stop
function returns True
for node
.
maxlevel (int): maximum descending in the node hierarchy.
Inherited Members
- anytree.iterators.abstractiter.AbstractIter
- AbstractIter
- node
- filter_
- stop
- maxlevel