Skip to content

Commit

Permalink
Removed redundant check mentioned in #8
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikP committed Aug 19, 2020
1 parent 6d9e41a commit acbe82f
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions src/ahocorapy/keywordtree.py
Expand Up @@ -147,28 +147,27 @@ def search_lss_for_children(self, zero_state):
to_process.append(child)

def search_lss(self, state):
if state.longest_strict_suffix is None:
parent = state.parent
traversed = parent.longest_strict_suffix
while True:
if state.symbol in traversed.transitions and\
traversed.transitions[state.symbol] != state:
state.longest_strict_suffix =\
traversed.transitions[state.symbol]
break
elif traversed == self._zero_state:
state.longest_strict_suffix = self._zero_state
break
else:
traversed = traversed.longest_strict_suffix
suffix = state.longest_strict_suffix
if suffix == self._zero_state:
return
if suffix.longest_strict_suffix is None:
self.search_lss(suffix)
for symbol, next_state in suffix.transitions.items():
if symbol not in state.transitions:
state.transitions[symbol] = next_state
parent = state.parent
traversed = parent.longest_strict_suffix
while True:
if state.symbol in traversed.transitions and\
traversed.transitions[state.symbol] != state:
state.longest_strict_suffix =\
traversed.transitions[state.symbol]
break
elif traversed == self._zero_state:
state.longest_strict_suffix = self._zero_state
break
else:
traversed = traversed.longest_strict_suffix
suffix = state.longest_strict_suffix
if suffix == self._zero_state:
return
if suffix.longest_strict_suffix is None:
self.search_lss(suffix)
for symbol, next_state in suffix.transitions.items():
if symbol not in state.transitions:
state.transitions[symbol] = next_state

def __str__(self):
return "ahocorapy KeywordTree"
Expand Down

0 comments on commit acbe82f

Please sign in to comment.