Skip to content

Create xxHash.py #11123

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

Closed
wants to merge 3 commits into from
Closed

Create xxHash.py #11123

wants to merge 3 commits into from

Conversation

sparshmanni
Copy link

@sparshmanni sparshmanni commented Oct 31, 2023

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label Oct 31, 2023
@cclauss cclauss added ON HOLD: Final hours of Hacktoberfest We will review this PR after Hacktoberfest has ended and removed ON HOLD: Final hours of Hacktoberfest We will review this PR after Hacktoberfest has ended labels Oct 31, 2023
@algorithms-keeper algorithms-keeper bot added the require type hints https://docs.python.org/3/library/typing.html label Nov 5, 2023
Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

PRIME32_5 = 0x165667B1


def xxhash(data, seed=0):

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: xxhash. 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

Please provide type hint for the parameter: seed

@algorithms-keeper algorithms-keeper bot added the awaiting reviews This PR is ready to be reviewed label Nov 5, 2023
PRIME32_5 = 0x165667B1


def xxhash(data, seed=0):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def xxhash(data, seed=0):
def xxhash(data: bytes, seed: int = 0) -> int:

Comment on lines +39 to +41
:param data: Data to be hashed (bytes)
:param seed: Seed value for the hash (integer)
:return: xxHash hash value (integer)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DRY: Don't repeat yourself

Suggested change
:param data: Data to be hashed (bytes)
:param seed: Seed value for the hash (integer)
:return: xxHash hash value (integer)
:param data: Data to be hashed
:param seed: Seed value for the hash
:return: xxHash hash value

Comment on lines +58 to +61
input_ints = list(
int.from_bytes(input_bytes, byteorder="little", signed=False)
for i in range(16)
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
input_ints = list(
int.from_bytes(input_bytes, byteorder="little", signed=False)
for i in range(16)
)
input_ints = [
int.from_bytes(input_bytes, byteorder="little", signed=False)
for i in range(16)
]

@algorithms-keeper algorithms-keeper bot added awaiting changes A maintainer has requested changes to this PR and removed awaiting reviews This PR is ready to be reviewed labels Nov 5, 2023
>>> data = b'Hello, World!'
>>> seed = 0
>>> xxhash(data, seed)
133790109
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

% python3 -m doctest -v hashes/xxhash.py

043     >>> data = b'Hello, World!'
044     >>> seed = 0
045     >>> xxhash(data, seed)
Expected:
    133790109
Got:
    159324916801739733393893190253682566781592874975429781715206986473506725566370079513040611836

@cclauss cclauss closed this Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting changes A maintainer has requested changes to this PR require type hints https://docs.python.org/3/library/typing.html tests are failing Do not merge until tests pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants