/// <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); }
public bool FindFirst(NodeMatch MatchingMethod) { try { return(this.LinearSearchForwardFromBeginning(MatchingMethod)); } catch { this.WriteToLog("Error finding first item"); return(false); } }
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); }
/// <summary> /// A linear search /// </summary> /// <param name="KeyToSearchFor">The index # to find in the list</param> /// <returns></returns> public bool FindFirstByIndex(long IndexToSearchFor) { try { //Create the default match criteron (a key) NodeMatch FindKey = new NodeMatch(IndexToSearchFor); //Now find it return(this.FindFirst(FindKey)); } catch { this.WriteToLog("Error finding key " + IndexToSearchFor.ToString()); return(false); } }
public bool FindNext(NodeMatch MatchingMethod) { try { if ((this._NodeCount > 1) && (!this.EOL)) { this.MoveNext(); return(this.LinearSearchForward(MatchingMethod)); } else { return(false); } } catch { this.WriteToLog("Error finding next item"); return(false); } }
public AVLTreeBase() : base() { this.DefaultMatchMethod = new NodeMatch(); }