forked from TheAlgorithms/Python
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelf.py
More file actions
Latest commit
21 lines (17 loc) · 440 Bytes
/
Copy pathelf.py
File metadata and controls
21 lines (17 loc) · 440 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
defelf_hash(data: str) ->int:
"""
Implementation of ElfHash Algorithm, a variant of PJW hash function.
>>> elf_hash('lorem ipsum')
253956621
"""
hash_=x=0
forletterindata:
hash_= (hash_<<4) +ord(letter)
x=hash_&0xF0000000
ifx!=0:
hash_^=x>>24
hash_&=~x
returnhash_
if__name__=="__main__":
importdoctest
doctest.testmod()