@@ -85,6 +85,9 @@ class FPTree(object):
85
85
This object may only store transaction items that are hashable (i.e., all
86
86
items must be valid as dictionary keys or set members).
87
87
"""
88
+
89
+ Route = namedtuple ('Route' , 'head tail' )
90
+
88
91
def __init__ (self ):
89
92
# The root node of the tree.
90
93
self ._root = FPNode (self , None , None )
@@ -130,10 +133,10 @@ def _update_route(self, point):
130
133
try :
131
134
route = self ._routes [point .item ]
132
135
route [1 ].neighbor = point # route[1] is the tail
133
- route [ 1 ] = point
136
+ self . _routes [ point . item ] = self . Route ( route [ 0 ], point )
134
137
except KeyError :
135
138
# First node for this item; start a new route.
136
- self ._routes [point .item ] = [ point , point ]
139
+ self ._routes [point .item ] = self . Route ( point , point )
137
140
138
141
def items (self ):
139
142
"""
@@ -180,13 +183,13 @@ def _removed(self, node):
180
183
# It was the sole node.
181
184
del self ._routes [node .item ]
182
185
else :
183
- self ._routes [node .item ][ 0 ] = node .neighbor
186
+ self ._routes [node .item ] = self . Route ( node .neighbor , tail )
184
187
else :
185
188
for n in self .nodes (node .item ):
186
189
if n .neighbor is node :
187
190
n .neighbor = node .neighbor # skip over
188
191
if node is tail :
189
- self ._routes [node .item ][ 1 ] = n
192
+ self ._routes [node .item ] = self . Route ( head , n )
190
193
break
191
194
192
195
def conditional_tree_from_paths (paths , minimum_support ):
0 commit comments