Exemplo n.º 1
0
        public bool LinearSearchForward(NodeMatch pMatchMethod)
        {
            bool           tmpMatchFound  = false;
            TimeSpanMetric tmpSearchTimer = new TimeSpanMetric();

            if (this._LogSearch)
            {
                tmpSearchTimer.Start();
            }

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

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

            return(tmpMatchFound);
        }
Exemplo n.º 2
0
        /// <summary>
        /// A forward linear search from the beginning of the list
        /// </summary>
        /// <param name="Matching_Method">A derivative of Node_Match that returns Match() as true on hits</param>
        /// <returns>True if anything was found</returns>
        public bool LinearSearchForwardFromBeginning(NodeMatch pMatchMethod)
        {
            bool tmpMatchFound = false;

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

                    //First see if we are already at the matching node
                    if (pMatchMethod.Match(this.CurrentNode))
                    {
                        this._SearchMatchCount++;
                        tmpMatchFound = true;
                    }
                    else
                    {
                        //Set the current node to the list head
                        this.MoveFirst();

                        //Now search forward and see if there are any hits
                        tmpMatchFound = this.LinearSearchForward(pMatchMethod);
                    }
                }
            }
            catch
            {
                this.WriteToLog("Error searching list of (" + this.Count.ToString() + ") items");
            }

            return(tmpMatchFound);
        }