MCPcopy Create free account
hub / github.com/python/cpython / _lookup

Method _lookup

Tools/unicode/dawg.py:158–178  ·  view source on GitHub ↗

Return an integer 0 <= k < number of strings in dawg where word is the kth successful traversal of the dawg.

(self, word)

Source from the content-addressed store, hash-verified

156 self.unchecked_nodes.pop()
157
158 def _lookup(self, word):
159 """ Return an integer 0 <= k < number of strings in dawg
160 where word is the kth successful traversal of the dawg. """
161 node = self.root
162 skipped = 0 # keep track of number of final nodes that we skipped
163 index = 0
164 while index < len(word):
165 for label, child in node.linear_edges:
166 if word[index] == label[0]:
167 if word[index:index + len(label)] == label:
168 if node.final:
169 skipped += 1
170 index += len(label)
171 node = child
172 break
173 else:
174 return None
175 skipped += child.num_reachable_linear
176 else:
177 return None
178 return skipped
179
180 def enum_all_nodes(self):
181 stack = [self.root]

Callers 1

_topological_orderMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected