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())