Skip to content

New Tree.children_itr method#118

Open
cowo78 wants to merge 2 commits intocaesar0301:masterfrom
cowo78:master
Open

New Tree.children_itr method#118
cowo78 wants to merge 2 commits intocaesar0301:masterfrom
cowo78:master

Conversation

@cowo78
Copy link
Copy Markdown

@cowo78 cowo78 commented Sep 12, 2019

In case creating a list like Tree.children() does is too heavy for efficiency reasons.

Giuseppe Corbelli added 2 commits September 12, 2019 10:23
case an iterator is preferrable over a list creation for efficiency
reasons.
nodes as its companion method Tree.children().
@cowo78 cowo78 requested a review from caesar0301 as a code owner September 12, 2019 08:29
@caesar0301
Copy link
Copy Markdown
Owner

It seems as duplicated as method children which could convert into an iterator via iter(childrenI())

@cowo78
Copy link
Copy Markdown
Author

cowo78 commented Dec 2, 2019

Not really. Doing an iter(children()) would first create a list then iterate over it while children_itr() would just create the iterator. In the first case memory usage is O(N), in the second is O(1).

@@ -296,6 +296,13 @@ def children(self, nid):
"""
return [self[i] for i in self.is_branch(nid)]
Copy link
Copy Markdown

@crabhi crabhi Mar 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High, just a quick note - this method could now be implemented equivalently as list(self.children_itr(nid)). That might address @caesar0301's comment re. redundancy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants