From 1b2233099db80b8c3a513d137045aae7de7a252f Mon Sep 17 00:00:00 2001 From: akiyamn Date: Sun, 2 May 2021 17:40:33 +1000 Subject: Ass 2: Comments --- ass2/q2/suffix_array.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'ass2/q2/suffix_array.py') diff --git a/ass2/q2/suffix_array.py b/ass2/q2/suffix_array.py index edfaa80..78cf6c4 100644 --- a/ass2/q2/suffix_array.py +++ b/ass2/q2/suffix_array.py @@ -3,6 +3,9 @@ import sys def depth_first_apply(node: Node, func): + """ + Apply a given function to every leaf node in the suffix tree via DFS + """ if not node.children: func(node.suffix_index) else: @@ -11,11 +14,17 @@ def depth_first_apply(node: Node, func): def read_in_string(filename): + """ + Reads in a string from a given file name + """ with open(filename, "r") as file: return file.read() def suffix_array(string): + """ + Generates a suffix array from a given string using Ukkonen's and a depth first search + """ tree = ukkonen(string) buffer = [] depth_first_apply(tree, buffer.append) @@ -23,6 +32,9 @@ def suffix_array(string): def write_suffix_array(string, filename): + """ + Writes a suffix array for a given string to a given file name. + """ with open(filename, "w") as file: buffer = suffix_array(string) file.write("\n".join(map(str, buffer))) -- cgit v1.2.3