コード例 #1
0
        void evalSearchResult(int depth = -1)
        {
            bool          isResult = false;
            List <string> result   = new List <string>();

            foreach (IndexNode t in searchResult)
            {
                if (t == null)
                {
                    result = null;
                    break;
                }
                if (isResult)
                {
                    result = intersection(result, t.files);
                    if (result.Count == 0)
                    {
                        break;
                    }
                }
                else
                {
                    result   = t.files;
                    isResult = true;
                }
            }
            main.showSentenceSearchResult(sentence, result, depth);
            main.openProgressBar(false);
        }
コード例 #2
0
        public TrieNode createChild(char c, IndexNode node)
        {
            TrieNode child = new TrieNode(c);

            child.indexData = node;
            children.Add(child);

            return(child);
        }
コード例 #3
0
        public async void search(string word, bool isWord = true)   // another thread for searching
        {
            await Task.Run(() => {
                int depth = -1;
                switch (method)
                {
                case 0:
                    result = bst.search(word);
                    depth  = bst.depth();
                    break;

                case 1:
                    result = tst.search(word);
                    depth  = tst.depth();
                    break;

                case 2:
                    result = trie.search(word);
                    depth  = trie.depth();
                    break;

                case 3:
                    result = hash.search(word);
                    depth  = -1;

                    break;

                default:
                    result = null;
                    break;
                }

                System.Windows.Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background,
                                                                          new Action(() => {
                    if (isWord)
                    {
                        main.showSearchResult(result, depth);
                    }
                    else
                    {
                        addSearchResult(result);
                        main.changeProgressBar(wordsToSearchCount - wordsToSearch.Count, wordsToSearchCount);
                        wordsToSearch.Remove(word);
                        if (wordsToSearch.Count > 0)
                        {
                            search(wordsToSearch[0], false);
                        }
                        else
                        {
                            evalSearchResult(depth);
                        }
                    }
                }));
            });
        }
コード例 #4
0
        void insert(IndexNode node)
        {
            TrieNode curr = root;

            curr = curr.getChild(node.word[0], node, true);

            for (int i = 1; i < node.word.Length; i++)
            {
                curr = curr.getChild(node.word[i], node, true);
            }
        }
コード例 #5
0
        BSTNode insert(BSTNode node, IndexNode t)
        {
            if (node == null)
            {
                return(new BSTNode(t));
            }

            string data = t.word;

            if (node.data.word.CompareTo(data) > 0)
            {
                node.lc = insert(node.lc, t);
            }
            else
            {
                node.rc = insert(node.rc, t);
            }

            node.height = Math.Max(getNodeHeight(node.lc), getNodeHeight(node.rc)) + 1;

            int diff = getNodeBalance(node);

            // Left Rotate
            if (diff > 1 && data.CompareTo(node.lc.data.word) < 0)
            {
                return(rRotate(node));
            }

            // Right Rotate
            if (diff < -1 && data.CompareTo(node.rc.data.word) > 0)
            {
                return(lRotate(node));
            }

            // Left Right Rotate
            if (diff > 1 && data.CompareTo(node.lc.data.word) > 0)
            {
                node.lc = lRotate(node.lc);
                return(rRotate(node));
            }

            // Right Left Rotate
            if (diff < -1 && data.CompareTo(node.rc.data.word) < 0)
            {
                node.rc = rRotate(node.rc);
                return(lRotate(node));
            }

            return(node);
        }
コード例 #6
0
        public TrieNode getChild(char c, IndexNode node, bool create = false)
        {
            foreach (var child in children)
            {
                if (child.data == c)
                {
                    return(child);
                }
            }

            if (create)
            {
                return(createChild(c, node));
            }

            return(null);
        }
コード例 #7
0
 internal int CompareTo(IndexNode s2)
 {
     return(word.CompareTo(s2.word));
 }
コード例 #8
0
 void insert(IndexNode node)
 {
     root = insert(root, node, 0);
 }
コード例 #9
0
 void addSearchResult(IndexNode word)
 {
     searchResult.Add(word);
 }
コード例 #10
0
 public BSTNode(IndexNode data)
 {
     this.data = data;
 }