예제 #1
0
        /// <summary>
        /// Merges the the index list <c>arrIndex</c> into the current one
        /// </summary>
        /// <param name="arrIndex">indexlist which should be merged with the current one</param>
        /// <param name="typeOfIndex">type of index to merge</param>
        public void MergeIndex(IList <HtmlHelpIndexItem> arrIndex, IndexType typeOfIndex)
        {
            IList <HtmlHelpIndexItem> _index = null;

            switch (typeOfIndex)
            {
            case IndexType.AssiciativeLinks:
                _index = _aLinks;
                break;

            case IndexType.KeywordLinks:
                _index = _kLinks;
                break;
            }

            Debug.WriteLine("Index.MergeIndex() ");
            Debug.Indent();
            DateTime dtStartM = DateTime.Now;

            foreach (HtmlHelpIndexItem curItem in arrIndex)
            {
                //IndexItem searchItem = ContainsIndex(_index, curItem.KeyWordPath);
                int insertIndex = 0;
                HtmlHelpIndexItem searchItem = BinSearch(0, _index.Count - 1, _index,
                                                         curItem.KeyWordPath, false, false, ref insertIndex);

                if (searchItem != null)
                {
                    // extend the keywords topics
                    foreach (HtmlHelpIndexTopic curEntry in curItem.Topics)
                    {
                        searchItem.Topics.Add(curEntry);
                    }
                }
                else
                {
                    // add the item to the global collection
                    //_index.Add( curItem );

                    if (insertIndex > _index.Count)
                    {
                        _index.Add(curItem);
                    }
                    else
                    {
                        _index.Insert(insertIndex, curItem);
                    }
                }
            }

            DateTime dtEndM   = DateTime.Now;
            TimeSpan elapsedM = dtEndM - dtStartM;

            Debug.WriteLine("--- Merge completed in " + elapsedM.ToString());
            Debug.Unindent();
        }
예제 #2
0
        /// <summary>
        /// Implements the compareto method which allows sorting.
        /// </summary>
        /// <param name="obj">object to compare to</param>
        /// <returns>See <see cref="System.IComparable">IComparable.CompareTo()</see></returns>
        public int CompareTo(object obj)
        {
            if (obj.GetType() == this.GetType())
            {
                HtmlHelpIndexItem cmp = (HtmlHelpIndexItem)obj;

                return(this.KeyWordPath.CompareTo(cmp.KeyWordPath));
            }

            return(0);
        }
예제 #3
0
        /// <summary>
        /// Searches the alinks- or klinks-index for a specific keyword/associative
        /// </summary>
        /// <param name="search">keyword/associative to search</param>
        /// <param name="typeOfIndex">type of index to search</param>
        /// <returns>Returns an list which contains IndexTopic items or null if nothing was found</returns>
        public HtmlHelpIndexItem SearchIndex(string search, IndexType typeOfIndex)
        {
            IList <HtmlHelpIndexItem> _index = null;

            switch (typeOfIndex)
            {
            case IndexType.AssiciativeLinks:
                _index = _aLinks;
                break;

            case IndexType.KeywordLinks:
                _index = _kLinks;
                break;
            }

            int insertIdx = 0;
            HtmlHelpIndexItem foundItem = BinSearch(0, _index.Count, _index,
                                                    search, true, true, ref insertIdx);

            return(foundItem);
        }
예제 #4
0
        /// <summary>
        /// Searches an index entry using recursive binary search algo (divide and conquer).
        /// </summary>
        /// <param name="nStart">start index for searching</param>
        /// <param name="nEnd">end index for searching</param>
        /// <param name="arrIndex">arraylist containing sorted IndexItem entries</param>
        /// <param name="keywordPath">keyword path to search</param>
        /// <param name="searchKeyword">true if the keywordPath will only contain the keyword not the complete path</param>
        /// <param name="caseInsensitive">True if case should be ignored</param>
        /// <param name="insertIndex">out reference. will receive the index where the item with the
        /// keywordPath should be inserted if not found (receives -1 if the item was found)</param>
        /// <returns>Returns an IndexItem instance if found, otherwise null
        /// (use insertIndex for inserting the new item in a sorted order)</returns>
        private HtmlHelpIndexItem BinSearch(int nStart, int nEnd, IList <HtmlHelpIndexItem> arrIndex, string keywordPath,
                                            bool searchKeyword, bool caseInsensitive, ref int insertIndex)
        {
            if (arrIndex.Count <= 0)
            {
                insertIndex = 0;
                return(null);
            }

            if (caseInsensitive)
            {
                keywordPath = keywordPath.ToLower();
            }

            if ((nEnd - nStart) > 1)
            {
                int nCheck = nStart + (nEnd - nStart) / 2;

                HtmlHelpIndexItem iC = arrIndex[nCheck];

                string sCompare = iC.KeyWordPath;

                if (searchKeyword)
                {
                    sCompare = iC.KeyWord;
                }

                if (caseInsensitive)
                {
                    sCompare = sCompare.ToLower();
                }

                if (sCompare == keywordPath)
                {
                    insertIndex = -1;
                    return(iC);
                }

                if (keywordPath.CompareTo(sCompare) < 0)
                {
                    return(BinSearch(nStart, nCheck - 1, arrIndex, keywordPath, searchKeyword, caseInsensitive, ref insertIndex));
                }

                if (keywordPath.CompareTo(sCompare) > 0)
                {
                    return(BinSearch(nCheck + 1, nEnd, arrIndex, keywordPath, searchKeyword, caseInsensitive, ref insertIndex));
                }
            }
            else if (nEnd - nStart == 1)
            {
                HtmlHelpIndexItem i1 = arrIndex[nStart];
                HtmlHelpIndexItem i2 = arrIndex[nEnd];

                string sCompare1 = i1.KeyWordPath;

                if (searchKeyword)
                {
                    sCompare1 = i1.KeyWord;
                }

                if (caseInsensitive)
                {
                    sCompare1 = sCompare1.ToLower();
                }

                string sCompare2 = i2.KeyWordPath;

                if (searchKeyword)
                {
                    sCompare2 = i2.KeyWord;
                }

                if (caseInsensitive)
                {
                    sCompare2 = sCompare2.ToLower();
                }

                if (sCompare1 == keywordPath)
                {
                    insertIndex = -1;
                    return(i1);
                }

                if (sCompare2 == keywordPath)
                {
                    insertIndex = -1;
                    return(i2);
                }

                if (sCompare1.CompareTo(keywordPath) > 0)
                {
                    insertIndex = nStart;
                    return(null);
                }
                else if (sCompare2.CompareTo(keywordPath) > 0)
                {
                    insertIndex = nEnd;
                    return(null);
                }
                else
                {
                    insertIndex = nEnd + 1;
                }
            }

            HtmlHelpIndexItem itm = arrIndex[nEnd];

            string sCompareI = itm.KeyWordPath;

            if (searchKeyword)
            {
                sCompareI = itm.KeyWord;
            }

            if (caseInsensitive)
            {
                sCompareI = sCompareI.ToLower();
            }

            if (sCompareI.CompareTo(keywordPath) > 0)
            {
                insertIndex = nStart;
                return(null);
            }
            else if (sCompareI.CompareTo(keywordPath) < 0)
            {
                insertIndex = nEnd + 1;
                return(null);
            }
            else
            {
                insertIndex = -1;
                return(arrIndex[nEnd]);
            }
        }