MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / elf_hash

Function elf_hash

hashes/elf.py:1–15  ·  view source on GitHub ↗

Implementation of ElfHash Algorithm, a variant of PJW hash function. >>> elf_hash('lorem ipsum') 253956621

(data: str)

Source from the content-addressed store, hash-verified

1def elf_hash(data: str) -> int:
2 """
3 Implementation of ElfHash Algorithm, a variant of PJW hash function.
4
5 >>> elf_hash('lorem ipsum')
6 253956621
7 """
8 hash_ = x = 0
9 for letter in data:
10 hash_ = (hash_ << 4) + ord(letter)
11 x = hash_ & 0xF0000000
12 if x != 0:
13 hash_ ^= x >> 24
14 hash_ &= ~x
15 return hash_
16
17
18if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected