Пример #1
0
        internal ICollection <SearchResult <TValue> > FindAll(DirectAccessList <ss_word_t> words)
        {
            var ss     = default(SortedSet <SearchResult <TValue> >);
            var finder = Finder.Create(_Root);

            for (int index = 0, len = words.Count; index < len; index++)
            {
                var node = finder.Find(words._Items[index].valueOriginal);

                if (node.HasNgrams)
                {
                    if (ss == null)
                    {
                        ss = new SortedSet <SearchResult <TValue> >(SearchResult <TValue> .Comparer.Instance);
                    }

                    foreach (var ngram in node.Ngrams)
                    {
                        var r = ss.Add(new SearchResult <TValue>(index - ngram.words.Length + 1, ngram.words.Length, ngram.value));
                        System.Diagnostics.Debug.Assert(r);
                    }
                }
            }
            if (ss != null)
            {
                return(ss);
            }
            return(EMPTY_RESULT_1);
        }
Пример #2
0
        /*internal int ValuesMaxLength
         * {
         *  get;
         *  private set;
         * }*/

        internal ICollection <SearchResult <TValue> > FindAll(DirectAccessList <ss_word_t> words)
        {
            var searchResults = default(SortedSet <SearchResult <TValue> >);

            TreeNode node = _Root;

            for (int index = 0, len = words.Count; index < len; index++)
            {
                TreeNode trans = null;
                while (trans == null)
                {
                    trans = node.GetTransition(words._Items[index].valueOriginal);
                    if (node == _Root)
                    {
                        break;
                    }
                    if (trans == null)
                    {
                        node = node.Failure;
                    }
                }
                if (trans != null)
                {
                    node = trans;
                }

                if (0 < node.Ngrams.Count)
                {
                    if (searchResults == null)
                    {
                        searchResults = new SortedSet <SearchResult <TValue> >(SearchResultIComparer.Instance);
                    }
                    //for ( int i = 0, len = node.Ngrams.Count; i < len; i++ )
                    foreach (var ngram in node.Ngrams)
                    {
                        var r = searchResults.Add(new SearchResult <TValue>(index - ngram.words.Length + 1, ngram.words.Length, ngram.value));
                        System.Diagnostics.Debug.Assert(r);
                    }
                }
            }
            if (searchResults != null)
            {
                return(searchResults);
            }
            return(EMPTY_RESULT_1);
        }