hashtable or map? (map inserts not behaving as I expect - and I cant
find a decent simple example for hashtable)
I have a list of items that I want to ignore during processing. I read a
list of items from file and populate a map variable. However, only a
subset of the items are being inserted in the map.
The struct for IgnoreItem looks like this:
struct IgnoreItem
{
//ctors and op== omitted for the sake of brevity
bool operator<(const IgnoreItem& key) const
{
if ( _stricmp(syb.c_str(), key.syb.c_str()) < 0)
return true;
else if (_stricmp(key.syb.c_str(), syb.c_str()) < 0)
return false;
else if ( xid < key.xid )
return true ;
else if ( key.xid < xid )
return false;
else if ( icid < key.icid)
return true ;
else
return key.icid < icid ;
}
std::string syb;
unsigned char xid ;
long icid ;
};
It seems that the map is inserting items with unique syb fields only.
For example, in my ignore-list file, I have 84 entries - however, when I
load into the map there are only 24 entries, each with a unique syb.
I would prefer to use a hashtable since it gives me constant time
access, and I will be doing my lookups in a loop - however, for the life
of me, I cant find any simple hash_map example that get straight to the
point and show how to do this. In the absence of any useful hash
examples, I would have been content with having to use std::map for now
- but it seems to be determing uniqueness based on the syb field alone -
Q1). Can anyone explain why only a subset of my ignore list is being
inserted? (whats wrong with the op< that I have implemented above)?
Q2). Can anyone provide a snippet that will show how can use hash_map
(or some other hashing container) to store the IgnoreItem items ?