Implementation of ElfHash Algorithm, a variant of PJW hash function. >>> elf_hash('lorem ipsum') 253956621
(data: str)
| 1 | def 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 | |
| 18 | if __name__ == "__main__": |
nothing calls this directly
no outgoing calls
no test coverage detected