Exemplo n.º 1
0
        /// <summary>
        /// Initialise the dictionary. This resets the tree held in memory, asks the user to select a folder of dictionary files and will save the
        /// new dictionary after it finishes scanning. Should be called from the main thread and will not block.
        /// </summary>
        private void InitialiseDictionary()
        {
            Tree = new DictTree();
            LabelDictionarySave.Text = DICT_LABEL_PROMPT + "0";

            AddDictMenu addDict = new AddDictMenu(this);

            addDict.ShowDialog();
        }
Exemplo n.º 2
0
        public DictTree BuildTree(IList <string> wordDict)
        {
            var root = new DictTree(' ');

            for (int i = wordDict.Count - 1; i >= 0; --i)
            {
                BuildTree(root, wordDict[i], 0, i);
            }
            return(root);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Attempt to load the default dictionary file. Should be called from the main thread and will not block.
        /// </summary>
        /// <returns>True if the dictionary file exists and is starting to be read, false if it can't be found</returns>
        private bool LoadDefaultDictionary()
        {
            Tree = new DictTree();
            String path = GetDictionaryPath();

            if (!File.Exists(path))
            {
                return(false);
            }

            PreDictionaryLoader(false);
            dictLoader.RunWorkerAsync(path);
            return(true);
        }
Exemplo n.º 4
0
 public void BuildTree(DictTree node, string word, int wi, int di)
 {
     if (!node.Childs.TryGetValue(word[wi], out DictTree child))
     {
         child = new DictTree(word[wi]);
         node.Childs.Add(word[wi], child);
     }
     if (wi == word.Length - 1)
     {
         child.Idx = di;
     }
     else
     {
         BuildTree(child, word, wi + 1, di);
     }
 }
Exemplo n.º 5
0
 public bool Dfs(string s, int si, DictTree root, DictTree node, List <int> listIdx)
 {
     if (si == s.Length)
     {
         if (root == node)
         {
             ans.Add(listIdx.ToArray());
         }
         return(true);
     }
     if (!node.Childs.TryGetValue(s[si], out DictTree child))
     {
         return(false);
     }
     Dfs(s, si + 1, root, child, listIdx);
     if (child.Idx != -1)
     {
         listIdx.Add(child.Idx);
         Dfs(s, si + 1, root, root, listIdx);
         listIdx.RemoveAt(listIdx.Count - 1);
     }
     return(false);
 }