diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-09-15 16:46:17 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-09-15 16:46:17 +0000 |
commit | 28cc22419e32a65fea2d1678400265b8cabc3aff (patch) | |
tree | ff9ac1991fd48490b21ef6aa9015a347a165e2d9 /sqlglot/trie.py | |
parent | Initial commit. (diff) | |
download | sqlglot-28cc22419e32a65fea2d1678400265b8cabc3aff.tar.xz sqlglot-28cc22419e32a65fea2d1678400265b8cabc3aff.zip |
Adding upstream version 6.0.4.upstream/6.0.4
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/trie.py')
-rw-r--r-- | sqlglot/trie.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/sqlglot/trie.py b/sqlglot/trie.py new file mode 100644 index 0000000..a234107 --- /dev/null +++ b/sqlglot/trie.py @@ -0,0 +1,27 @@ +def new_trie(keywords): + trie = {} + + for key in keywords: + current = trie + + for char in key: + current = current.setdefault(char, {}) + current[0] = True + + return trie + + +def in_trie(trie, key): + if not key: + return (0, trie) + + current = trie + + for char in key: + if char not in current: + return (0, current) + current = current[char] + + if 0 in current: + return (2, current) + return (1, current) |