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); }
private void SendTelnetAlphaWordList(TelnetServerCommandEventArgs pEventArgs, string pSearchString) { bool tmpListingCompleted = false; int tmpMatchCount = 0; MutiTimeSpan tmpSearchTimer = new MutiTimeSpan(); if (_WordList.Count > 0) { _TelnetServer.SendData(" Word List:", pEventArgs.Socket); _TelnetServer.SendLineFeed(pEventArgs.Socket); _TelnetServer.SendData("--- Number - Word ------------------------------- Alphagram -------------=====", pEventArgs.Socket); _TelnetServer.SendLineFeed(pEventArgs.Socket); tmpListingCompleted = !_WordList.FindFirstByAlphagram(pSearchString); while (!tmpListingCompleted) { //This display function is assuming that the words are no longer than 28 characters which is safe for scrabble words _TelnetServer.SendData(String.Format(" {0,8}. {1,-32} {2}", _WordList.CurrentItemKey, _WordList.CurrentWord, _WordList.CurrentWordAlphagram), pEventArgs.Socket); _TelnetServer.SendLineFeed(pEventArgs.Socket); tmpMatchCount++; //Bail out of the listing if it's the end of the list tmpListingCompleted = _WordList.EOL; //This is to not display the last node if it isn't a match and we hit the EOL tmpListingCompleted = !_WordList.FindNextByAlphagram(pSearchString); } _TelnetServer.SendData("==========================================================================-----", pEventArgs.Socket); _TelnetServer.SendLineFeed(pEventArgs.Socket); _TelnetServer.SendData(tmpMatchCount.ToString() + " Word(s) Matched the Pattern " + pSearchString, pEventArgs.Socket); _TelnetServer.SendLineFeed(pEventArgs.Socket); tmpSearchTimer.TimeStamp(); _TelnetServer.SendData("Effective Time To Search: " + tmpSearchTimer.TimeDifference.ToString() + "ms", pEventArgs.Socket); _TelnetServer.SendLineFeed(pEventArgs.Socket); } else { _TelnetServer.SendData("The word list is empty.", pEventArgs.Socket); _TelnetServer.SendLineFeed(pEventArgs.Socket); } }