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

Skip to content

Commit a6e1303

Browse files
author
Eric Naeseth
committed
New properties: FPTree#root gives access to the tree's root node, and FPNode#leaf is true iff the node is a leaf in its tree.
1 parent f5fffda commit a6e1303

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

fp_growth.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ def __init__(self):
2323
# "neighbors" that will hit every node containing that item.
2424
self._routes = {}
2525

26+
@property
27+
def root(self):
28+
"""The root node of the tree."""
29+
return self._root
30+
2631
def add(self, transaction):
2732
"""
2833
Adds a transaction to the tree.
@@ -133,6 +138,11 @@ def root(self):
133138
"""True if this node is the root of a tree; false if otherwise."""
134139
return self._item is None and self._count is None
135140

141+
@property
142+
def leaf(self):
143+
"""True if this node is a leaf in the tree; false if otherwise."""
144+
return len(self._children) == 0
145+
136146
def parent():
137147
doc = "The node's parent."
138148
def fget(self):

0 commit comments

Comments
 (0)