-
-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Adding ELFHash Algorithm #6731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding ELFHash Algorithm #6731
Changes from 7 commits
38bd19f
fbac99b
7666acc
c26969a
71b5e8e
1f03436
0cc859c
09a6e1c
636de59
efc745c
3dcdad1
62eefeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
def elf_hash(data): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: Please provide type hint for the parameter: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: Please provide type hint for the parameter: |
||
""" | ||
Implementation of ElfHash Algorithm, a variant of PJW hash function. | ||
|
||
Returns: | ||
[int] -- [32 bit binary int] | ||
>>> elf_hash('lorem ipsum') | ||
253956621 | ||
""" | ||
hash = x = i = 0 | ||
micaelalex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for i in range(len(data)): | ||
hash = (hash << 4) + ord(data[i]) | ||
micaelalex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
x = hash & 0xF0000000 | ||
if x != 0: | ||
hash ^= x >> 24 | ||
hash &= ~x | ||
return hash | ||
|
||
|
||
if __name__ == "__main__": | ||
import doctest | ||
|
||
doctest.testmod() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function:
elf_hash
. If the function does not return a value, please provide the type hint as:def function() -> None:
Please provide type hint for the parameter:
data