Re: Is there a faster way to fetch data from stl map?
On Dec 27, 8:24 pm, blargg....@gishpuppy.com (blargg) wrote:
tni wrote:
[...]> struct hash {
size_t operator()(int a) const {
a = (a ^ 61) ^ (a >> 16);
a = a + (a << 3);
a = a ^ (a >> 4);
a = a * 0x27d4eb2d;
a = a ^ (a >> 15);
return a;
}
};
[...]
Your hash function would be more portable if you used unsigned
int, since signed int can overflow in the expressions you use.
More to the point: how are the integer values distributed. If
they're dense, then just using an std::vector would be even
better than a hash table. If they're more or less randomly
distributed, just returning the integral value, converted to
size_t, would be a lot faster than his code, and just as
effective. (His function is really a good example of how not to
implement a hash function.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34