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

Skip to content

Commit f5fffda

Browse files
author
Eric Naeseth
committed
Finish the internal terminology change (path -> route), and factor out the route updating code.
1 parent 2ec8b02 commit f5fffda

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

fp_growth.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,21 @@ def add(self, transaction):
4242
next_point = FPNode(self, item)
4343
point.add(next_point)
4444

45-
# Update the path of nodes that contain this item to include
45+
# Update the route of nodes that contain this item to include
4646
# our new node.
47-
try:
48-
path = self._routes[item]
49-
path[1].neighbor = next_point # path[1] is the tail
50-
path[1] = next_point
51-
except KeyError:
52-
# First node for this item; start a new path.
53-
self._routes[item] = [next_point, next_point]
47+
self._update_route(next_point)
5448

5549
point = next_point
5650

51+
def _update_route(self, point):
52+
try:
53+
route = self._routes[point.item]
54+
route[1].neighbor = point # route[1] is the tail
55+
route[1] = point
56+
except KeyError:
57+
# First node for this item; start a new route.
58+
self._routes[point.item] = [point, point]
59+
5760
def nodes(self, item):
5861
"""
5962
Generates the sequence of nodes that contain the given item.

0 commit comments

Comments
 (0)