Esempio n. 1
0
        public bool Add(Word4 item)
        {
            Dictionary <char, Dictionary <char, HashSet <char> > > level2;

            if (!this.data.TryGetValue(item.L1, out level2))
            {
                level2 = new Dictionary <char, Dictionary <char, HashSet <char> > >();
                this.data.Add(item.L1, level2);
            }

            Dictionary <char, HashSet <char> > level3;

            if (!level2.TryGetValue(item.L2, out level3))
            {
                level3 = new Dictionary <char, HashSet <char> >();
                level2.Add(item.L2, level3);
            }

            HashSet <char> level4;

            if (!level3.TryGetValue(item.L3, out level4))
            {
                level4 = new HashSet <char>();
                level3.Add(item.L3, level4);
            }

            return(level4.Add(item.L4));
        }
Esempio n. 2
0
 private void DoColumn3(Word4 column3, Word4Grid grid, Action <Word4Grid> onFound)
 {
     if (this.allowDuplicateWords || (!grid.Row1.Equals(column3) && !grid.Column1.Equals(column3) && !grid.Row2.Equals(column3) && !grid.Column2.Equals(column3) && !grid.Row3.Equals(column3)))
     {
         grid = new Word4Grid(grid.Row1, grid.Row2, grid.Row3, new Word4(grid.A30, grid.A31, column3.L4, '\0'));
         this.trie.Match3(grid.A30, grid.A31, grid.A32, w => this.DoRow4(w, grid, onFound));
     }
 }
Esempio n. 3
0
 private void DoColumn2(Word4 column2, Word4Grid grid, Action <Word4Grid> onFound)
 {
     if (this.allowDuplicateWords || (!grid.Row1.Equals(column2) && !grid.Column1.Equals(column2) && !grid.Row2.Equals(column2)))
     {
         grid = new Word4Grid(grid.Row1, grid.Row2, new Word4(grid.A20, column2.L3, '\0', '\0'), new Word4(grid.A30, column2.L4, '\0', '\0'));
         this.trie.Match2(grid.A20, grid.A21, w => this.DoRow3(w, grid, onFound));
     }
 }
Esempio n. 4
0
 private void DoColumn1(Word4 column1, Word4Grid grid, Action <Word4Grid> onFound)
 {
     if (this.allowDuplicateWords || !grid.Row1.Equals(column1))
     {
         grid = new Word4Grid(grid.Row1, new Word4(column1.L2, '\0', '\0', '\0'), new Word4(column1.L3, '\0', '\0', '\0'), new Word4(column1.L4, '\0', '\0', '\0'));
         this.trie.Match1(grid.A10, w => this.DoRow2(w, grid, onFound));
     }
 }
Esempio n. 5
0
 private void DoRow4(Word4 row4, Word4Grid grid, Action <Word4Grid> onFound)
 {
     grid = new Word4Grid(grid.Row1, grid.Row2, grid.Row3, row4);
     if (this.allowDuplicateWords || (!grid.Row1.Equals(row4) && !grid.Column1.Equals(row4) && !grid.Row2.Equals(row4) && !grid.Column2.Equals(row4) && !grid.Row3.Equals(row4) && !grid.Column3.Equals(row4) && !grid.Column4.Equals(row4)))
     {
         if (this.trie.Contains(grid.Column4))
         {
             onFound(grid);
         }
     }
 }
Esempio n. 6
0
 public static void Load(string line, Action <Word4> onWordFound)
 {
     foreach (string s in line.Split(WhitespaceChars, StringSplitOptions.RemoveEmptyEntries))
     {
         if (s.Length == 4)
         {
             Word4 word = new Word4(s);
             onWordFound(word);
         }
     }
 }
Esempio n. 7
0
 private static void MatchInner(char l1, char l2, Dictionary <char, HashSet <char> > level3, Action <Word4> onMatch)
 {
     foreach (KeyValuePair <char, HashSet <char> > level34 in level3)
     {
         char l3 = level34.Key;
         foreach (char l4 in level34.Value)
         {
             Word4 word = new Word4(l1, l2, l3, l4);
             onMatch(word);
         }
     }
 }
Esempio n. 8
0
 public Word4Grid(Word4 row1, Word4 row2, Word4 row3, Word4 row4)
 {
     this.a00 = row1.L1;
     this.a01 = row1.L2;
     this.a02 = row1.L3;
     this.a03 = row1.L4;
     this.a10 = row2.L1;
     this.a11 = row2.L2;
     this.a12 = row2.L3;
     this.a13 = row2.L4;
     this.a20 = row3.L1;
     this.a21 = row3.L2;
     this.a22 = row3.L3;
     this.a23 = row3.L4;
     this.a30 = row4.L1;
     this.a31 = row4.L2;
     this.a32 = row4.L3;
     this.a33 = row4.L4;
 }
Esempio n. 9
0
        public bool Contains(Word4 item)
        {
            bool found = false;
            Dictionary <char, Dictionary <char, HashSet <char> > > level2;

            if (this.data.TryGetValue(item.L1, out level2))
            {
                Dictionary <char, HashSet <char> > level3;
                if (level2.TryGetValue(item.L2, out level3))
                {
                    HashSet <char> level4;
                    if (level3.TryGetValue(item.L3, out level4))
                    {
                        found = level4.Contains(item.L4);
                    }
                }
            }

            return(found);
        }
Esempio n. 10
0
        public bool Remove(Word4 item)
        {
            bool removed = false;
            Dictionary <char, Dictionary <char, HashSet <char> > > level2;

            if (this.data.TryGetValue(item.L1, out level2))
            {
                Dictionary <char, HashSet <char> > level3;
                if (level2.TryGetValue(item.L2, out level3))
                {
                    HashSet <char> level4;
                    if (level3.TryGetValue(item.L3, out level4))
                    {
                        removed = level4.Remove(item.L4);
                    }
                }
            }

            return(removed);
        }
Esempio n. 11
0
        public void Match3(char l1, char l2, char l3, Action <Word4> onMatch)
        {
            if (onMatch == null)
            {
                throw new ArgumentNullException("onMatch");
            }

            Dictionary <char, Dictionary <char, HashSet <char> > > level2;
            Dictionary <char, HashSet <char> > level3;
            HashSet <char> level4;

            if (this.data.TryGetValue(l1, out level2) && level2.TryGetValue(l2, out level3) && level3.TryGetValue(l3, out level4))
            {
                foreach (char l4 in level4)
                {
                    Word4 word = new Word4(l1, l2, l3, l4);
                    onMatch(word);
                }
            }
        }
Esempio n. 12
0
        public static void Load(string line1, string line2, string line3, string line4, Action <Word4Grid> onGridFound)
        {
            string[] row1 = line1.Split(SpaceChar, StringSplitOptions.RemoveEmptyEntries);
            string[] row2 = line2.Split(SpaceChar, StringSplitOptions.RemoveEmptyEntries);
            string[] row3 = line3.Split(SpaceChar, StringSplitOptions.RemoveEmptyEntries);
            string[] row4 = line4.Split(SpaceChar, StringSplitOptions.RemoveEmptyEntries);

            int minLength = row1.Length;

            if (row2.Length < minLength)
            {
                minLength = row2.Length;
            }

            if (row3.Length < minLength)
            {
                minLength = row3.Length;
            }

            if (row4.Length < minLength)
            {
                minLength = row4.Length;
            }

            for (int i = 0; i < minLength; ++i)
            {
                if ((row1[i].Length == 4) && (row2[i].Length == 4) && (row3[i].Length == 4) && (row4[i].Length == 4))
                {
                    Word4 wr1 = new Word4(row1[i]);
                    Word4 wr2 = new Word4(row2[i]);
                    Word4 wr3 = new Word4(row3[i]);
                    Word4 wr4 = new Word4(row4[i]);

                    Word4Grid grid = new Word4Grid(wr1, wr2, wr3, wr4);
                    onGridFound(grid);
                }
            }
        }
Esempio n. 13
0
        public void Find(Word4 input, Action <Word4Grid> onFound)
        {
            Word4Grid grid = new Word4Grid(input, new Word4(), new Word4(), new Word4());

            this.trie.Match1(grid.A00, w => this.DoColumn1(w, grid, onFound));
        }