Click here to Skip to main content
15,920,801 members
Home / Discussions / C#
   

C#

 
GeneralRe: Better Way to Search for a Value in a List of KeyValuePairs??? Pin
NickPace7-Sep-11 12:42
NickPace7-Sep-11 12:42 
GeneralRe: Better Way to Search for a Value in a List of KeyValuePairs??? Pin
Matt U.7-Sep-11 13:12
Matt U.7-Sep-11 13:12 
QuestionRe: Better Way to Search for a Value in a List of KeyValuePairs??? Pin
MicroVirus8-Sep-11 4:34
MicroVirus8-Sep-11 4:34 
AnswerRe: Better Way to Search for a Value in a List of KeyValuePairs??? Pin
Abhinav S7-Sep-11 8:26
Abhinav S7-Sep-11 8:26 
AnswerRe: Better Way to Search for a Value in a List of KeyValuePairs??? Pin
Ian Shlasko7-Sep-11 10:06
Ian Shlasko7-Sep-11 10:06 
AnswerRe: Better Way to Search for a Value in a List of KeyValuePairs??? Pin
PIEBALDconsult7-Sep-11 14:25
mvePIEBALDconsult7-Sep-11 14:25 
AnswerRe: Better Way to Search for a Value in a List of KeyValuePairs??? Pin
Mehdi Gholam7-Sep-11 20:05
Mehdi Gholam7-Sep-11 20:05 
AnswerRe: Better Way to Search for a Value in a List of KeyValuePairs??? [modified] Pin
BillWoodruff7-Sep-11 20:38
professionalBillWoodruff7-Sep-11 20:38 
This is the kind of question and discussion I'd so enjoy seeing more of on this forum, thanks, Nick.

It would be fascinating to know how the different techniques suggested here, including Ennis' suggestion of using a HashTable, compare in terms of speed and efficiency. This discussion on StackOverFlow may be relevant (?): [^]

In this case we don't know whether every string in each KeyValuePair is unique or not, and that could influence the gamut of solutions ?

Here's my suggestion, but I'm no Linq master:
C#
List<KeyValuePair<Guid, string>> kvpList = new List<KeyValuePair<Guid, string>>();

private IEnumerable<string> sList;

private void testKVPToList()
{
    for (int i = 1000; i < 2000; i++)
    {
        Guid guid = new Guid("F4168C51-CEB2-4EBC-B6BF-319B339D" + i.ToString());
        kvpList.Add(new KeyValuePair<Guid, string>(guid,(i*5).ToString()));
    }

    sList = from kvp in kvpList select kvp.Value;

    if(sList.Contains("5000")) Console.WriteLine("5000 found");
    if(sList.Contains("9995")) Console.WriteLine("9995 found");
}


Whether 'tis better to take a 'one-time' hit and build a List, or to dynamically look-up on-the-fly: that's a good question ! And, if the goal is to build the fastest List to search ? My casual attempt to make a SortedList from a KeyValuePair List resulted in a pig that could not fly, but I'm sure there's a way Smile | :)

I'd certainly go and examine Mehdi Gholam's recent 'Hoot' full-text search be-all-and-end-all project[^], and see what he's doing there, because I'll bet it's as optimized as possible.

You can find some implementations of the Boyer-Moore algorithm here on CP:[^].
"Is it a fact - or have I dreamt it - that, by means of electricity, the world of matter has become a great nerve, vibrating thousands of miles in a breathless point of time? Rather, the round globe is a vast head, a brain, instinct with intelligence!" - Nathanial Hawthorne, House of the Seven Gables
modified on Thursday, September 8, 2011 2:45 AM

GeneralRe: Better Way to Search for a Value in a List of KeyValuePairs??? Pin
NickPace8-Sep-11 3:40
NickPace8-Sep-11 3:40 
QuestionC#.net expiration date Pin
classy_dog7-Sep-11 5:30
classy_dog7-Sep-11 5:30 
AnswerRe: C#.net expiration date Pin
GParkings7-Sep-11 5:37
GParkings7-Sep-11 5:37 
GeneralRe: C#.net expiration date Pin
classy_dog7-Sep-11 5:51
classy_dog7-Sep-11 5:51 
GeneralRe: C#.net expiration date Pin
GParkings7-Sep-11 6:20
GParkings7-Sep-11 6:20 
GeneralRe: C#.net expiration date Pin
kribo9-Sep-11 5:01
professionalkribo9-Sep-11 5:01 
Questionout of memory ! Pin
mersad007-Sep-11 4:34
mersad007-Sep-11 4:34 
AnswerRe: out of memory ! Pin
GParkings7-Sep-11 4:45
GParkings7-Sep-11 4:45 
AnswerRe: out of memory ! Pin
Pete O'Hanlon7-Sep-11 5:01
mvePete O'Hanlon7-Sep-11 5:01 
AnswerRe: out of memory ! Pin
#realJSOP7-Sep-11 7:23
professional#realJSOP7-Sep-11 7:23 
AnswerRe: out of memory ! Pin
Daniel.Grondal7-Sep-11 22:43
Daniel.Grondal7-Sep-11 22:43 
QuestionThread.join Pin
benams7-Sep-11 0:28
benams7-Sep-11 0:28 
AnswerRe: Thread.join Pin
Pete O'Hanlon7-Sep-11 0:57
mvePete O'Hanlon7-Sep-11 0:57 
QuestionAre thre Mutex's that can be used in Silverlight? Pin
Xarzu6-Sep-11 7:59
Xarzu6-Sep-11 7:59 
AnswerRe: Are thre Mutex's that can be used in Silverlight? Pin
Pete O'Hanlon6-Sep-11 8:23
mvePete O'Hanlon6-Sep-11 8:23 
AnswerRe: Are thre Mutex's that can be used in Silverlight? Pin
Abhinav S6-Sep-11 19:34
Abhinav S6-Sep-11 19:34 
QuestionWhat is the Regular expression that detects a $ sign and digits in html code Pin
Member 82168286-Sep-11 7:21
Member 82168286-Sep-11 7:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.