Пример #1
0
        public bool LinearSearchForward(NodeMatch MatchingMethod)
        {
            bool         MatchedItem = false;
            MutiTimeSpan SearchTimer = new MutiTimeSpan();

            if (this._LogSearches)
            {
                SearchTimer.Start();
            }

            try
            {
                if (this.Count > 0)
                {
                    //Now walk through the list until we either find it or hit the end.
                    while ((!MatchingMethod.Match(this.CurrentNode)) && (!this.EOL))
                    {
                        this.MoveNext();
                    }

                    //See if we found it or not
                    if (MatchingMethod.Match(this.CurrentNode))
                    {
                        this._SearchMatchCount++;
                        MatchedItem = true;
                    }
                }
            }
            catch
            {
                this.WriteToLog("Error during forward linear searching list of (" + this.Count.ToString() + ") items");
            }
            finally
            {
                if (this._LogSearches)
                {
                    SearchTimer.TimeStamp();
                    if (MatchedItem)
                    {
                        this.WriteToLog("Searched Forward in a list of (" + this.Count.ToString() + ") items and found item #" + this.CurrentItemKey.ToString() + " taking " + SearchTimer.TimeDifference.ToString() + "ms.");
                    }
                    else
                    {
                        this.WriteToLog("Searched Forward in a list of (" + this.Count.ToString() + ") items and did not get a match taking " + SearchTimer.TimeDifference.ToString() + "ms.");
                    }
                }
            }

            return(MatchedItem);
        }
Пример #2
0
        /// <summary>
        /// A forward linear search from the beginning of the list
        /// </summary>
        /// <param name="MatchingMethod">A derivative of NodeMatch that returns Match() as true on hits</param>
        /// <returns>True if anything was found</returns>
        public bool LinearSearchForwardFromBeginning(NodeMatch MatchingMethod)
        {
            bool MatchedItem = false;

            try
            {
                if (_NodeCount > 0)
                {
                    //Update the statistics
                    this._SearchCount++;

                    //First see if we are already at the matching node
                    if (MatchingMethod.Match(this.CurrentNode))
                    {
                        this._SearchMatchCount++;
                        MatchedItem = true;
                    }
                    else
                    {
                        //Set the current node to the list head
                        this.MoveFirst();
                        //Now search forward and see if there are any hits
                        MatchedItem = this.LinearSearchForward(MatchingMethod);
                    }
                }
            }
            catch
            {
                this.WriteToLog("Error searching list of (" + this.Count.ToString() + ") items");
            }

            return(MatchedItem);
        }