Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5803128

Browse files
committed
Add some inspection methods
1 parent 4ddfe44 commit 5803128

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

fp_growth.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,17 @@ def collect_path(node):
174174

175175
return (collect_path(node) for node in self.nodes(item))
176176

177+
def inspect(self):
178+
print 'Tree:'
179+
self.root.inspect(1)
180+
181+
print
182+
print 'Routes:'
183+
for item, nodes in self.items():
184+
print ' %r' % item
185+
for node in nodes:
186+
print ' %r' % node
187+
177188
def _removed(self, node):
178189
"""Called when `node` is removed from the tree; performs cleanup."""
179190

@@ -366,6 +377,10 @@ def children(self):
366377
"""The nodes that are children of this node."""
367378
return tuple(self._children.itervalues())
368379

380+
def inspect(self, depth=0):
381+
print (' ' * depth) + repr(self)
382+
for child in self.children:
383+
child.inspect(depth + 1)
369384

370385
def __repr__(self):
371386
if self.root:

0 commit comments

Comments
 (0)