Why might stable_sort be affecting my hashtable values?

Posted by zebraman on Stack Overflow See other posts from Stack Overflow or by zebraman
Published on 2010-04-01T23:08:53Z Indexed on 2010/04/01 23:13 UTC
Read the original article Hit count: 379

Filed under:
|
|

I have defined a struct ABC to contain an int ID, string NAME, string LAST_NAME;
My procedure is this: Read in a line from an input file. Parse each line into first name and last name and insert into the ABC struct. Also, the struct's ID is given by the number of the input line.

Then, push_back the struct into a vector masterlist. I am also hashing these to a hashtable defined as vector< vector >, using first name and last name as keywords. That is,

If my data is:
Garfield Cat
Snoopy Dog
Cat Man

Then for the keyword cash hashes to a vector containing Garfield Cat and Cat Man. I insert the structs into the hashtable using push_back again.

The problem is, when I call stable_sort on my masterlist, my hashtable is affected for some reason. I thought it might be happening since the songs are being ordered differently, so I tried making a copy of the masterlist and sorting it and it still affects the hashtable though the original masterlist is unaffected.

Any ideas why this might be happening?

© Stack Overflow or respective owner

Related posts about stable-sort

Related posts about hashtable