Hash Function

Categories: containers, functors

Component type: concept

Description

A Hash Function is a Unary Function that is used by Hashed Associative Containers: it maps its argument to a result of type size_t. A Hash Function must be deterministic and stateless. That is, the return value must depend only on the argument, and equal arguments must yield equal results.

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 size_t should be roughly the same as the probability that it returns any other value. [1]

Refinement of

Unary Function

Associated types
Result type The type returned when the Hash Function is called. The result type must be size_t.
Valid expressions

None, except for those described in the Unary Function requirements.

Invariants
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.
Models

• hash

Notes

[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.

See also

Hashed Associative Container, hash

Unique Associative Container

Category: containers

Component type: concept

Description

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.

Refinement of

Associative Container

Associated types

None, except for those defined by Associative Container.

Notation

X A type that is a model of Unique Associative Container

a Object of type X

t Object of type X::value_type

k Object of type X::key_type

p, q Object of type X::iterator

Valid expressions

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); i and j are Input Iterators whose value type is convertible to T [1]
Insert element a.insert(t) pair<X::iterator, bool>
Insert range a.insert(i, j) i and j are Input Iterators whose value type is convertible to X::value_type. [1] void
Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату