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!
=== Identity hash function === If the data to be hashed is small enough, then one can use the data itself (reinterpreted as an integer) as the hashed value. The cost of computing this ''[[identity function|identity]]'' hash function is effectively zero. This hash function is [[Perfect hash function|perfect]], as it maps each input to a distinct hash value. The meaning of "small enough" depends on the size of the type that is used as the hashed value. For example, in [[Java (programming language)|Java]], the hash code is a 32-bit integer. Thus the 32-bit integer <code>Integer</code> and 32-bit floating-point <code>Float</code> objects can simply use the value directly, whereas the 64-bit integer <code>Long</code> and 64-bit floating-point <code>Double</code> cannot. Other types of data can also use this hashing scheme. For example, when mapping [[character string]]s between [[letter case|upper and lower case]], one can use the binary encoding of each character, interpreted as an integer, to index a table that gives the alternative form of that character ("A" for "a", "8" for "8", etc.). If each character is stored in 8 bits (as in [[extended ASCII]]<ref group=Notes>Plain [[ASCII]] is a 7-bit character encoding, although it is often stored in 8-bit bytes with the highest-order bit always clear (zero). Therefore, for plain ASCII, the bytes have only 2<sup>7</sup> = 128 valid values, and the character translation table has only this many entries.</ref> or [[ISO Latin 1]]), the table has only 2<sup>8</sup> = 256 entries; in the case of [[Unicode]] characters, the table would have 17 Γ 2<sup>16</sup> = {{Val|1114112}} entries. The same technique can be used to map [[ISO 3166-1 alpha-2|two-letter country codes]] like "us" or "za" to country names (26<sup>2</sup> = 676 table entries), 5-digit [[ZIP Code|ZIP codes]] like 13083 to city names ({{val|100000}} entries), etc. Invalid data values (such as the country code "xx" or the ZIP code 00000) may be left undefined in the table or mapped to some appropriate "null" value.
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)