Hash Function
Categories: containers, functors
Component type: concept
A Hash Function is a Unary Function that is used by Hashed Associative Containers: it maps its argument to a result of type
The performance of a Hashed Associative Container depends crucially on its hash function. It is important for a Hash Function to minimize collisions, where a collision is defined as two different arguments that hash to the same value. It is also important that the distribution of hash values be uniform; that is, the probability that a Hash Function returns any particular value of type
Unary Function
Result type | The type returned when the Hash Function is called. The result type must be |
None, except for those described in the Unary Function requirements.
Deterministic function | The return value depends only on the argument, as opposed to the past history of the Hash Function object. The return value is always the same whenever the argument is the same. |
• hash
[1] Note that both of these requirements make sense only in the context of some specific distribution of input values. To take a simple example, suppose that the values being hashed are the six strings 'aardvark', 'trombone', 'history', 'diamond', 'forthright', and 'solitude'. In this case, one reasonable (and efficient) hash function would simply be the first character of each string. On the other hand, suppose that the values being hashed are 'aaa0001', 'aaa0010', 'aaa0011', 'aaa0100', 'aaa0101', and 'aaa0110'. In that case, a different hash function would be more appropriate. This is why Hashed Associative Containers are parameterized by the hash function: no one hash function is best for all applications.
Hashed Associative Container,
Unique Associative Container
Category: containers
Component type: concept
A Unique Associative Container is an Associative Container with the property that each key in the container is unique: no two elements in a Unique Associative Container have the same key.
Associative Container
None, except for those defined by Associative Container.
X
A type that is a model of Unique Associative Container
a
Object of type
t
Object of type
k
Object of type
p, q
Object of type
In addition to the expressions defined in Associative Container, the following expressions must be valid.
Name | Expression | Type requirements | Return type |
---|---|---|---|
Range constructor | X(i, j) X a(i, j); | ||
Insert element | a.insert(t) | pair<X::iterator, bool> | |
Insert range | a.insert(i, j) | void | |