Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public bool FindFirst(NodeMatch pMatchMethod)
        {
            try
            {
                return(this.LinearSearchForwardFromBeginning(pMatchMethod));
            }
            catch
            {
                this.WriteToLog("Error finding first item");

                return(false);
            }
        }
Exemplo n.º 3
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.º 4
0
        /// <summary>
        /// A linear search
        /// </summary>
        /// <param name="Key_To_Search_For">The index # to find in the list</param>
        /// <returns></returns>
        public bool FindFirstByIndex(long pIndexToSearchFor)
        {
            try
            {
                //Create the default match criteron (a key)
                NodeMatch tmpSearchingNode = new NodeMatch(pIndexToSearchFor);

                //Now find it
                return(this.FindFirst(tmpSearchingNode));
            }
            catch
            {
                this.WriteToLog("Error finding key " + pIndexToSearchFor.ToString());

                return(false);
            }
        }
Exemplo n.º 5
0
        public bool FindNext(NodeMatch pMatchMethod)
        {
            try
            {
                if ((this._NodeCount > 1) && (!this.EOL))
                {
                    this.MoveNext();

                    return(this.LinearSearchForward(pMatchMethod));
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                this.WriteToLog("Error finding next item");

                return(false);
            }
        }