c++ - What is the "right" way to use a GUID as the key in std::hash_map -


i want say

std::hash_map<guid, int> foo; 

i believe must create

bool operator < (const guid &guid1, const guid &guid2); std::size_t hash_value(guid const &b); 

what proper way compare guids? (memcmp?) - proper way generate hash?

it'd great if flesh out these 2 functions, i've read dozens of posts give final clue :-)

from documentation seems that:

typedef struct _guid {   dword data1;   word  data2;   word  data3;   byte  data4[8]; } guid; 

there several possibilities

building own

for comparison i'd go item item

bool operator < (const guid &guid1, const guid &guid2) {     if(guid1.data1!=guid2.data1) {         return guid1.data1 < guid2.data1;     }     if(guid1.data2!=guid2.data2) {         return guid1.data2 < guid2.data2;     }     if(guid1.data3!=guid2.data3) {         return guid1.data3 < guid2.data3;     }     for(int i=0;i<8;i++) {         if(guid1.data4[i]!=guid2.data4[i]) {             return guid1.data4[i] < guid2.data4[i];         }     }     return false; } 

for hashing... i'd go uuidhash function (note guid form of uuid indicated in uuid definition)

going strings

use stringfromclsid string guids... once have string, have operators.

... more expensive.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -