Prev: dependencies
Next: Determine type of member variable
From: vladutz on 10 Feb 2010 08:11 I want to use a structure like this: std::map<std::pair<unsigned int, const wchar_t*>, wchar_t*> how fast is the search ? The use of the std::pair is a performance issue ? thanks ins advance -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Jeff Schwab on 11 Feb 2010 02:15 vladutz wrote: > I want to use a structure like this: std::map<std::pair<unsigned int, > const wchar_t*>, wchar_t*> > > how fast is the search ? O(ln2 n), assuming O(1) key comparisons. > The use of the std::pair is a performance issue ? No, why would it be? Compared to what? -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Ulrich Eckhardt on 11 Feb 2010 02:14 vladutz wrote: > I want to use a structure like this: std::map<std::pair<unsigned int, > const wchar_t*>, wchar_t*> The problem I have with this is: 1. Who owns the memory pointed to? 2. Is this supposed to compare strings or pointer values? > how fast is the search ? The use of the std::pair is a performance > issue ? A std::pair is like a structure containing the two elements, so there is no overhead from it. Uli -- Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Joe Gottman on 11 Feb 2010 02:15 vladutz wrote: > I want to use a structure like this: std::map<std::pair<unsigned int, > const wchar_t*>, wchar_t*> > > how fast is the search ? The use of the std::pair is a performance > issue ? > > thanks ins advance > The search on the map is O(log N). Using a pair is as fast as using a hand-rolled struct containing the same two types. Assuming that the const wchar_t* and wchar_t * are dynamically-allocated C style strings, you might want to replace these with wstrings. Otherwise you could have a problem with managing the strings' lifetimes (i.e knowing when to call free or delete[]). Joe Gottman -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Bart van Ingen Schenau on 11 Feb 2010 02:14 On Feb 11, 2:11 am, vladutz <cprogram...(a)gmail.com> wrote: > I want to use a structure like this: std::map<std::pair<unsigned int, > const wchar_t*>, wchar_t*> > > how fast is the search ? The use of the std::pair is a performance > issue ? The search will be pretty fast. std::pair<> is not known to be a performance bottleneck. OTOH, the chances that you will actually find the item you are looking for is also pretty slim. The second part of your pair (the 'const wchar_t*' element) will be compared using an address-match comparisson. It, most notably, does NOT do a string-compare. > > thanks ins advance > Bart v Ingen Schenau -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
|
Pages: 1 Prev: dependencies Next: Determine type of member variable |