blob: 1c6743380392df53ae96445c1d3aea3fff87a716 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
from ass2.ukkonen import Node, ukkonen
def rank(char):
return ord("a") - ord(char) if char != "$" else 26
# tree = ukkonen("abacabad")
# # tree.print_tree()
# for node in Node.all_nodes:
# if not node.children:
# print(node)
def depth_first_apply(node: Node, func):
if not node.children:
func(node.suffix_index)
else:
for child in node.children.ordered_items():
depth_first_apply(child, func)
# def calc_suffix_index():
# lookup = {}
# counter = 0
# # leaves = filter(lambda n: not n.children, Node.all_nodes)
# for node in Node.all_nodes:
# if not node.children:
# lookup
#
# print(list(leaves))
def accum():
array = []
depth_first_apply(tree, lambda x: array.append(x))
return array
tree = ukkonen("mississippi")
print(accum())
|