MCPcopy Index your code
hub / github.com/python/cpython / _linearize_edges

Method _linearize_edges

Tools/unicode/dawg.py:219–237  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

217 assert 0
218
219 def _linearize_edges(self):
220 # compute "linear" edges. the idea is that long chains of edges without
221 # any of the intermediate states being final or any extra incoming or
222 # outgoing edges can be represented by having removing them, and
223 # instead using longer strings as edge labels (instead of single
224 # characters)
225 incoming = defaultdict(list)
226 nodes = sorted(self.enum_all_nodes(), key=lambda e: e.id)
227 for node in nodes:
228 for label, child in sorted(node.edges.items()):
229 incoming[child].append(node)
230 for node in nodes:
231 node.linear_edges = []
232 for label, child in sorted(node.edges.items()):
233 s = [label]
234 while len(child.edges) == 1 and len(incoming[child]) == 1 and not child.final:
235 (c, child), = child.edges.items()
236 s.append(c)
237 node.linear_edges.append((''.join(s), child))
238
239 def _topological_order(self):
240 # compute reachable linear nodes, and the set of incoming edges for each node

Callers 1

finishMethod · 0.95

Calls 5

enum_all_nodesMethod · 0.95
defaultdictClass · 0.85
itemsMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected