Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 Other versions  





2 Algorithm  





3 Implementation  





4 See also  





5 References  














PJW hash function







Add links
 









Article
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Cite this page
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 


PJW hash function is a non-cryptographic hash function created by Peter J. Weinberger of AT&T Bell Labs.

Other versions[edit]

A variant of PJW hash had been used to create ElfHash or Elf64 hash that is used in Unix object files with ELF format.

Allen Holub has created a portable version of PJW hash algorithm that had a bug and ended up in several textbooks, as the author of one of these textbooks later admitted.[1]

Algorithm[edit]

PJW hash algorithm involves shifting the previous hash and adding the current byte followed by moving the high bits:[2]

algorithm PJW_hash(s) is
    uint h := 0
    bits := uint size in bits
    for i := 1 to |S| do
        h := h << bits/8 + s[i]
        high := get top bits/8 bits of h from left
        if high ≠ 0 then
            h := h xor (high >> bits * 3/4)
            h := h & ~high
    returnh

Implementation[edit]

Below is the algorithm implementation used in Unix ELF format:[3]

unsigned long ElfHash(const unsigned char *s)
{
    unsigned long   h = 0, high;
    while (*s)
    {
        h = (h << 4) + *s++;
        if (high = h & 0xF0000000)
            h ^= high >> 24;
        h &= ~high;
    }
    return h;
}

This C code incorrectly assumes that long is a 32-bit data type. When long is wider than 32 bits, as it is on many 64-bit systems, the code contains a bug.[4]

See also[edit]

Non-cryptographic hash functions

References[edit]

  1. ^ Binstock, Andrew (1996). "Hashing Rehashed". Dr. Dobb's.
  • ^ "Hash Functions". www.cs.hmc.edu. Retrieved 2015-06-10.
  • ^ CORPORATE UNIX Press (1993). System V application binary interface. ISBN 0-13-100439-5.
  • ^ "ELF hash function may overflow". Retrieved 2023-04-14.

  • Retrieved from "https://en.wikipedia.org/w/index.php?title=PJW_hash_function&oldid=1174285380"

    Category: 
    Hash function (non-cryptographic)
    Hidden categories: 
    Articles with short description
    Short description matches Wikidata
    Articles with example pseudocode
    Articles with example C code
     



    This page was last edited on 7 September 2023, at 13:53 (UTC).

    Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



    Privacy policy

    About Wikipedia

    Disclaimers

    Contact Wikipedia

    Code of Conduct

    Developers

    Statistics

    Cookie statement

    Mobile view



    Wikimedia Foundation
    Powered by MediaWiki