示例#1
0
        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));
        }
示例#2
0
        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));
        }
示例#3
0
        private ValidWord GetValid(string word)
        {
            WordVertex vertex  = vertices[word];
            Fix        one     = vertex.OneFixes;
            Fix        twoMore = twoMoreFixes[word];

            return(new ValidWord(word, one, twoMore));
        }
示例#4
0
 private void AddEdgesIfNeeded(WordVertex vertex)
 {
     if (vertex.Word.Length == 1)
     {
         return;
     }
     AddPrefixEdge(vertex);
     AddSuffixEdge(vertex);
 }
示例#5
0
 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;
 }
示例#6
0
        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);
        }