Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Hash function
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Variable range === In many applications, the range of hash values may be different for each run of the program or may change along the same run (for instance, when a hash table needs to be expanded). In those situations, one needs a hash function which takes two parameters—the input data {{math|''z''}}, and the number {{math|''n''}} of allowed hash values. A common solution is to compute a fixed hash function with a very large range (say, {{math|0}} to {{math|2<sup>32</sup> − 1}}), divide the result by {{math|''n''}}, and use the division's [[modulo operation|remainder]]. If {{math|''n''}} is itself a power of {{math|2}}, this can be done by [[Mask (computing)|bit masking]] and [[bit shifting]]. When this approach is used, the hash function must be chosen so that the result has fairly uniform distribution between {{math|0}} and {{math|''n'' − 1}}, for any value of {{math|''n''}} that may occur in the application. Depending on the function, the remainder may be uniform only for certain values of {{math|''n''}}, e.g. [[odd number|odd]] or [[prime number]]s.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)