walk_groups() behavior (group return order)

Skip to first unread message


Mar 11, 2021, 12:46:31 PM3/11/21
to pytables-users
I'm working with Group.walk_groups() function and trying to understand the term "preorder" in this statement:"walks self top to bottom (preorder), iterating over child groups in alphanumerical order". (Source Ref: def _f_walk_groups(self): in source for tables.group).
This is what I have observed. The top level groups are returned in alphabetical order. Then, when Child groups are returned they are in reverse alphabetical order (from top to bottom). So when I have this structure:

This is the output order I get when I loop on  :
/ (RootGroup)
/group1 (Group)
/group2 (Group)
/group3 (Group)
/group3/group31 (Group)
/group3/group31/group311 (Group)
/group2/group21 (Group)
/group2/group22 (Group)
/group2/group22/group221 (Group)
/group2/group21/group211 (Group)
/group1/group11 (Group)
/group1/group12 (Group)

I reviewed the source and discovered this is a result of the way the group stack is popped (w/ stack.pop() to pop the last element). Is there a reason stack.pop(0) is not used?

Reply all
Reply to author
0 new messages