takashi
Member
|
std::map<Str8, int>.find() behaviour
Hi,
I found std::map<Str8, int>.find() doesn't work properly.
* In case of std::string
-------------------------------
typedef std::map<std::string, int> CueMap;
CueMap _cueMap;
std::string key = cueName;
_cueMap.insert( std::make_pair( key, grpNo ) );
CueMap::iterator it = _cueMap.find(key); // FOUND
-------------------------------
* In case of Str8
-------------------------------
typedef std::map<Str8, int> CueMap;
CueMap _cueMap;
Str8 key = cueName;
_cueMap.insert( std::make_pair( key, grpNo ) );
CueMap::iterator it = _cueMap.find(key); // NOT FOUND!!
-------------------------------
I suppose Str8's compare operator is not implemented properly.
Is it expected behaviour?
Thanks,
Takashi
|
|
06-22-2016 03:05 AM |
|
Esenthel
Administrator
|
RE: std::map<Str8, int>.find() behaviour
Hello,
I never use std::map so I don't know.
I use EE::Map, and EE::Compare functions to compare strings.
|
|
06-22-2016 05:27 AM |
|
takashi
Member
|
RE: std::map<Str8, int>.find() behaviour
Hi,
(06-22-2016 05:27 AM)Esenthel Wrote: Hello,
I never use std::map so I don't know.
I use EE::Map, and EE::Compare functions to compare strings.
EE::Map has no iterator, doesn't it?
In addition, I want to get key and value pair like std::pair.
Or should I use std::map<std::string, int> instead?
Thanks,
Takashi
|
|
06-22-2016 07:03 AM |
|
Esenthel
Administrator
|
RE: std::map<Str8, int>.find() behaviour
I recommend using these methods:
Code:
void lock ( )C; // lock elements container, unlock must be called after locking container
C KEY & lockedKey ( Int i )C; // access i-th element key from container, this can be used after locking and before unlocking the container
DATA& lockedData( Int i ) ; // access i-th element data from container, this can be used after locking and before unlocking the container
C DATA& lockedData( Int i )C; // access i-th element data from container, this can be used after locking and before unlocking the container
void unlock ( )C; // unlock elements container, this must be called after locking the container
http://www.esenthel.com/?id=doc#API/Memory/Map
|
|
06-22-2016 09:49 AM |
|
takashi
Member
|
RE: std::map<Str8, int>.find() behaviour
I'm afraid that the lock is slow and might cause performance issue.
|
|
06-22-2016 10:42 AM |
|
Zervox
Member
|
RE: std::map<Str8, int>.find() behaviour
Have you performance profiled it to see if it actually is an issue?
(This post was last modified: 06-22-2016 02:07 PM by Zervox.)
|
|
06-22-2016 02:07 PM |
|
Esenthel
Administrator
|
RE: std::map<Str8, int>.find() behaviour
The 'lock' and 'unlock' are optional, and don't need to be called, as long as you will call 'Map' methods only on one thread at the same time.
|
|
06-22-2016 03:18 PM |
|
takashi
Member
|
[EXPLAINED] std::map<Str8, int>.find() behaviour
(06-22-2016 03:18 PM)Esenthel Wrote: The 'lock' and 'unlock' are optional, and don't need to be called, as long as you will call 'Map' methods only on one thread at the same time.
OK. I'll use lockedData.
Thanks a lot!
|
|
06-23-2016 07:26 AM |
|