Hash: Merge documentation changes.

[SVN r76533]
This commit is contained in:
Daniel James
2012-01-15 20:49:40 +00:00
parent 5385cc4cd4
commit 40c9e2be58
2 changed files with 11 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
[library Boost.Functional/Hash [library Boost.Functional/Hash
[quickbook 1.4] [quickbook 1.5]
[authors [James, Daniel]] [authors [James, Daniel]]
[copyright 2005 2006 2007 2008 Daniel James] [copyright 2005 2006 2007 2008 Daniel James]
[purpose A TR1 hash function object that can be extended to hash user [purpose A TR1 hash function object that can be extended to hash user

View File

@@ -5,10 +5,10 @@
[section:rationale Rationale] [section:rationale Rationale]
The rationale for the design can be found in the original design The rationale can be found in the original design
[footnote issue 6.18 of the __issues__ (page 63)], but an issue that [footnote issue 6.18 of the __issues__ (page 63)].
occasionally comes up is the quality of the hash function, so that
demands some more attention. [heading:quality Quality of the hash function]
Many hash functions strive to have little correlation between the input Many hash functions strive to have little correlation between the input
and output values. They attempt to uniformally distribute the output and output values. They attempt to uniformally distribute the output
@@ -16,23 +16,23 @@ values for very similar inputs. This hash function makes no such
attempt. In fact, for integers, the result of the hash function is often attempt. In fact, for integers, the result of the hash function is often
just the input value. So similar but different input values will often just the input value. So similar but different input values will often
result in similar but different output values. result in similar but different output values.
This means that it is not appropriate as a general hash function. For This means that it is not appropriate as a general hash function. For
example, a hash table may discard bits from the hash function resulting example, a hash table may discard bits from the hash function resulting
in likely collisions, or might have poor collision resolution when hash in likely collisions, or might have poor collision resolution when hash
values are clustered together. In such cases this hash function will values are clustered together. In such cases this hash function will
preform poorly. preform poorly.
So why not implement a higher quality hash function? Well, the standard But the standard has no such requirement for the hash function,
makes no such guarantee, it just requires that the hashes of two it just requires that the hashes of two different values are unlikely
different values are unlikely to collide. Containers or algorithms to collide. Containers or algorithms
designed to work with the standard hash function will have to be designed to work with the standard hash function will have to be
implemented to work well when the hash function's output is correlated implemented to work well when the hash function's output is correlated
to its input. Since they are paying that cost a higher quality hash function to its input. Since they are paying that cost a higher quality hash function
would be wasteful. would be wasteful.
For other use cases, if you do need a higher quality hash function, For other use cases, if you do need a higher quality hash function,
there are several options then neither the standard hash function or `boost::hash` are appropriate.
There are several options
available. One is to use a second hash on the output of this hash available. One is to use a second hash on the output of this hash
function, such as [@http://www.concentric.net/~ttwang/tech/inthash.htm function, such as [@http://www.concentric.net/~ttwang/tech/inthash.htm
Thomas Wang's hash function]. This this may not work as Thomas Wang's hash function]. This this may not work as
@@ -47,4 +47,4 @@ your data - providing that all equal values have an equal
representation, which is not always the case (e.g. for floating point representation, which is not always the case (e.g. for floating point
values). values).
[endsect] [endsect]