Pergunta

Why do I need to implement both the == operator and a random operator returning a size_t? And what should the method returning size_t actually return?

EDIT: When I said random operator, I didn't mean it had no use. What I meant is, in my eyes, I do not see what use it has, hence the last question. 7

Foi útil?

Solução

A hashed container (hashtable, hashmap, unordered map) uses a hash-function to generate a single integer value to represent an index (or key) for the entry. This makes for a very quick-lookup, since (assuming we have a good spread of hash values) once we have the hash, we just need to look at that index. Most other storage methods means comparing a bunch of things until the right element is found.

There is really only two rules about hash-keys: 1. You get the same key for a given input each time the hash-function is called. 2. The value is different for different input - it doesn't HAVE to be unique, but the more spread you get from similar input, the better.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top