private void AddSuffixEdge(WordVertex vertex) { string suffix = vertex.Word.Substring(1); WordVertex suffixVertex = GetVertex(suffix, false); suffixVertex.Add(new FixEdge(vertex.Word[0], Fix.Prefix, vertex)); }
private void AddPrefixEdge(WordVertex vertex) { string prefix = vertex.Word.Substring(0, vertex.Word.Length - 1); WordVertex prefixVertex = GetVertex(prefix, false); prefixVertex.Add(new FixEdge(vertex.Word[prefix.Length], Fix.Suffix, vertex)); }
private ValidWord GetValid(string word) { WordVertex vertex = vertices[word]; Fix one = vertex.OneFixes; Fix twoMore = twoMoreFixes[word]; return(new ValidWord(word, one, twoMore)); }
private void AddEdgesIfNeeded(WordVertex vertex) { if (vertex.Word.Length == 1) { return; } AddPrefixEdge(vertex); AddSuffixEdge(vertex); }
public FixEdge(char letter, Fix fix, WordVertex vertex) { if (fix != Fix.Prefix && fix != Fix.Suffix) { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid fixes : {0}", fix), "fix"); } this.letter = letter; this.fix = fix; this.vertex = vertex; }
private WordVertex GetVertex(string word, bool valid) { WordVertex vertex; if (vertices.TryGetValue(word, out vertex)) { if (valid) { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "{0} already found but not valid (are words sorted by size?)", word), "valid"); } return(vertex); } vertex = new WordVertex(word, valid); vertices.Add(word, vertex); AddEdgesIfNeeded(vertex); return(vertex); }