What hash function are you using? The performance of dense_hash_map
is particularly sensitive to the choice of hash function. If you're
using the gcc default hash function, try using something like
mumurhash (fastest) or fnv (least code) instead.
craig
Hmm, may need more data to diagnose, then. If you look in
time_hash_map, in the sparsehash src directory, you can see a
structure that keeps track of how many hashes and key-comparisons are
being done. You could try adding diagnostics like this to your key,
or else just instrumenting your version of densehashtable.h directly,
to see if the problem is that it's requiring lots of lookups or
hashes.
If you can post some source code that illustrates the problem, that
might be helpful too. It would need to be a minimal, but runnable,
program, though.
craig
Are you just using strcmp() to compare keys, or something else?
One method you could use, if it's just that your keys are very big
strings, so comparing them is very slow, is that you could fingerprint
your keys, and store the fingerprints in your set. (You may also need
a map to get from fingerprint back to original string.) Then
comparisons will be fast, though you'll have some risk of two strings
having the same fingerprint. A good fingerprint function can reduce
the odds.
craig
craig
} I'm using the dense hashmap with a string key for searching in a
} 300.000 set. In order to find an element with the [] or find()
} method it takes about 500 milisecs.What hash function are you using? The performance of dense_hash_map
is particularly sensitive to the choice of hash function.
Yes, though since sparse_hash_map is optimized for size, not speed, it
tends not to matter as much. In both cases, though, I'd be wary of
using the identity hash without thinking about whether it will be ok.
craig