77# HELPERS #
88
99
10- def _get_child_branches (tr ):
11- return tr [1 :]
10+ def _get_child_branches (trie ):
11+ return trie [1 :]
1212
1313
14- def _get_child_branch (tr , c ):
14+ def _get_child_branch (trie , c ):
1515 """
1616 Find matching branch with the character
1717 """
18- for branch in _get_child_branches (tr ):
18+ for branch in _get_child_branches (trie ):
1919 if branch [0 ] == c :
2020 return branch
2121
2222 return None
2323
2424
25- def _retrive_branch (k , trie_list ):
25+ def _retrive_branch (k , trie ):
2626 if not k :
2727 return None
28- tr = trie_list
28+
2929 for c in k :
30- child_branch = _get_child_branch (tr , c )
30+ child_branch = _get_child_branch (trie , c )
3131 if not child_branch :
3232 return None
33- tr = child_branch
33+ trie = child_branch
3434
35- return tr
35+ return trie
3636
3737
3838def _is_trie_bucket (bucket ):
@@ -51,40 +51,40 @@ def _get_bucket_key(bucket):
5151# HAS_KEY #
5252
5353
54- def has_key (k , tr ):
55- return _retrive_branch (k , tr ) is not None
54+ def has_key (k , trie ):
55+ return _retrive_branch (k , trie ) is not None
5656
5757# RETRIE_VAL
5858
5959
60- def retrie_val (k , tr ):
61- key_tuple = _retrive_branch (k , tr )
60+ def retrie_val (k , trie ):
61+ key_tuple = _retrive_branch (k , trie )
6262 if not key_tuple :
6363 return None
6464
6565 return key_tuple [1 ]
6666
6767
68- def insert_key (key , v , trie_list ):
69- if not key or has_key (key , trie_list ):
68+ def insert_key (key , v , trie ):
69+ if not key or has_key (key , trie ):
7070 return
7171
72- tr = trie_list
7372 for char in key :
74- branch = _get_child_branch (tr , char )
73+ branch = _get_child_branch (trie , char )
7574 if not branch :
7675 new_branch = [char ]
77- tr .append (new_branch )
78- tr = new_branch
76+ trie .append (new_branch )
77+ trie = new_branch
7978 else :
80- tr = branch
81- tr .append ((key , v ))
79+ trie = branch
80+ trie .append ((key , v ))
8281
8382
8483def start_with_prefix (prefix , trie ):
8584 branch = _retrive_branch (prefix , trie )
8685 if not branch :
8786 return []
87+
8888 prefix_list = []
8989 q = branch [1 :]
9090 while q :
0 commit comments