Update the FP-Tree with a transaction. Args: items: List of items in the transaction. in_tree: The current node in the FP-Tree. header_table: The header table dictionary with item information. count: The count of the transaction. Example: >>> data_s
(items: list, in_tree: TreeNode, header_table: dict, count: int)
| 126 | |
| 127 | |
| 128 | def update_tree(items: list, in_tree: TreeNode, header_table: dict, count: int) -> None: |
| 129 | """ |
| 130 | Update the FP-Tree with a transaction. |
| 131 | |
| 132 | Args: |
| 133 | items: List of items in the transaction. |
| 134 | in_tree: The current node in the FP-Tree. |
| 135 | header_table: The header table dictionary with item information. |
| 136 | count: The count of the transaction. |
| 137 | |
| 138 | Example: |
| 139 | >>> data_set = [ |
| 140 | ... ['A', 'B', 'C'], |
| 141 | ... ['A', 'C'], |
| 142 | ... ['A', 'B', 'E'], |
| 143 | ... ['A', 'B', 'C', 'E'], |
| 144 | ... ['B', 'E'] |
| 145 | ... ] |
| 146 | >>> min_sup = 2 |
| 147 | >>> fp_tree, header_table = create_tree(data_set, min_sup) |
| 148 | >>> fp_tree |
| 149 | TreeNode('Null Set', 1, None) |
| 150 | >>> transaction = ['A', 'B', 'E'] |
| 151 | >>> update_tree(transaction, fp_tree, header_table, 1) |
| 152 | >>> fp_tree |
| 153 | TreeNode('Null Set', 1, None) |
| 154 | >>> fp_tree.children['A'].children['B'].children['E'].children |
| 155 | {} |
| 156 | >>> fp_tree.children['A'].children['B'].children['E'].count |
| 157 | 2 |
| 158 | >>> header_table['E'][1].name |
| 159 | 'E' |
| 160 | """ |
| 161 | if items[0] in in_tree.children: |
| 162 | in_tree.children[items[0]].inc(count) |
| 163 | else: |
| 164 | in_tree.children[items[0]] = TreeNode(items[0], count, in_tree) |
| 165 | if header_table[items[0]][1] is None: |
| 166 | header_table[items[0]][1] = in_tree.children[items[0]] |
| 167 | else: |
| 168 | update_header(header_table[items[0]][1], in_tree.children[items[0]]) |
| 169 | if len(items) > 1: |
| 170 | update_tree(items[1:], in_tree.children[items[0]], header_table, count) |
| 171 | |
| 172 | |
| 173 | def update_header(node_to_test: TreeNode, target_node: TreeNode) -> TreeNode: |
no test coverage detected