From: vladutz on
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
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
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
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
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! ]