Exemple #1
0
// lrs_h is a helper function for computing the longest repeated
// substring
func lrs_h(raw_content string) string {

	content := sp.Preprocess_string(raw_content)
	prefix_array := sp.Make_prefix_array(content)
	sp.String_quicksort(prefix_array)
	return longest_repeated_substring(prefix_array)
}
Exemple #2
0
// get_matches returns all matches for word filtered according
// to the provided command line flags
func get_matches(input, word string) []string {

	// process, create prefix array and sort
	content := sp.Preprocess_string(string(input))
	prefix_array := sp.Make_prefix_array(content)
	sp.String_quicksort(prefix_array)

	matches := make([]string, 0)
	length := len(content)
	i := sp.Binary_search(prefix_array, word)

	// found a match
	if i >= 0 {

		raw_matches := sp.Scan_array(prefix_array, word, i)
		if exact_match {
			for _, match := range raw_matches {
				match_index := length - len(match)

				// throw out matches starting in the middle of a word
				if match_index != 0 && content[match_index-1] != ' ' {
					continue
				} else if match_index <= length-2 &&
					content[match_index+len(word)] != ' ' {
					continue
				} else {
					matches = append(matches, match)
				}
			}
		} else {
			matches = raw_matches
		}
	}

	return matches
}