From 29170655e07d11eb5b3c9276cb2c973f5359e843 Mon Sep 17 00:00:00 2001
From: Denis Barbier <barbier@imacs.polytechnique.fr>
Date: Thu, 2 Jan 2020 13:14:03 +0100
Subject: [PATCH] Replace _FixedLengthTrie by set

This is now possible because tuples are hashable.
---
 mlxtend/frequent_patterns/apriori.py | 42 ++--------------------------
 1 file changed, 2 insertions(+), 40 deletions(-)

diff --git a/mlxtend/frequent_patterns/apriori.py b/mlxtend/frequent_patterns/apriori.py
index f8c4ac6d7..777ba6ba4 100644
--- a/mlxtend/frequent_patterns/apriori.py
+++ b/mlxtend/frequent_patterns/apriori.py
@@ -9,44 +9,6 @@
 from ..frequent_patterns import fpcommon as fpc
 
 
-class _FixedLengthTrie:
-
-    """Fixed-length trie (prefix tree).
-
-    Parameters
-    ----------
-    combinations: list of itemsets
-        All combinations with enough support in the last step
-
-    Attributes
-    ----------
-    root : dict
-        Root node
-    """
-    __slots__ = ("root")
-
-    def __init__(self, combinations):
-        self.root = dict()
-        for combination in combinations:
-            current = self.root
-            for item in combination:
-                try:
-                    current = current[item]
-                except KeyError:
-                    next_node = dict()
-                    current[item] = next_node
-                    current = next_node
-
-    def __contains__(self, combination):
-        current = self.root
-        try:
-            for item in combination:
-                current = current[item]
-            return True
-        except KeyError:
-            return False
-
-
 def generate_new_combinations(old_combinations):
     """
     Generator of all combinations based on the last state of Apriori algorithm
@@ -79,7 +41,7 @@ def generate_new_combinations(old_combinations):
     """
 
     length = len(old_combinations)
-    trie = _FixedLengthTrie(old_combinations)
+    set_old_combinations = set(old_combinations)
     for i, old_combination in enumerate(old_combinations):
         head_i = list(old_combination[:-1])
         j = i + 1
@@ -94,7 +56,7 @@ def generate_new_combinations(old_combinations):
             for idx in range(len(candidate) - 2):
                 test_candidate = list(candidate)
                 del test_candidate[idx]
-                if test_candidate not in trie:
+                if tuple(test_candidate) not in set_old_combinations:
                     # early exit from for-loop skips else clause just below
                     break
             else: