add performance optimisation
This commit is contained in:
@@ -17,15 +17,33 @@ def probe(key, substrings, words):
|
||||
return {key: val for key, val in key_hits.items() if val == best_val}
|
||||
|
||||
|
||||
def remove_crap_from_list(tree, max_depth, thr):
|
||||
best = [0 for x in range(max_depth+1)]
|
||||
for key, val in tree.items():
|
||||
if val > best[len(key)]:
|
||||
best[len(key)] = val
|
||||
|
||||
import copy
|
||||
tmp = copy.copy(list(tree.items()))
|
||||
for key, val in tmp:
|
||||
if val < (best[len(key)] - thr):
|
||||
del tree[key]
|
||||
|
||||
|
||||
def crack(substrings, words):
|
||||
tree = {"": 0}
|
||||
while tree:
|
||||
curr = [key for key, val in sorted(
|
||||
tree.items(), key=lambda ele: ele[1])][-1]
|
||||
print(curr)
|
||||
if len(curr) == len(substrings[0]):
|
||||
return curr
|
||||
del tree[curr]
|
||||
tree.update(probe(curr, substrings, words))
|
||||
print(tree)
|
||||
remove_crap_from_list(tree, len(substrings[0]), 10)
|
||||
print(tree)
|
||||
print()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user