Skip to content
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 multibit-manipulation algorithm implemented with bitwise operations #11418

Open
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

billbreit
Copy link

Describe your change:

  • [x ] 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?

Checklist:

  • [ x] I have read CONTRIBUTING.md.
  • [x ] This pull request is all my own work -- I have not plagiarized.
  • [x ] I know that pull requests will not be merged if they fail the automated tests.
  • [ x] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • [x ] All new Python files are placed inside an existing directory.
  • [x ] All filenames are in all lowercase characters with no spaces or dashes.
  • [ x] All functions and variable names follow Python naming conventions.
  • [x ] All function parameters and return values are annotated with Python type hints.
  • [ x] All functions have doctests that pass the automated testing.
  • [x ] All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

@algorithms-keeper algorithms-keeper bot added awaiting reviews This PR is ready to be reviewed tests are failing Do not merge until tests pass and removed tests are failing Do not merge until tests pass labels May 28, 2024
billbreit and others added 5 commits May 28, 2024 20:14
Blank lines with spaces, trailing spaces at end of line, etc.
Is it or isn't it ?
Seems to be OK so far ...
@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label May 29, 2024
@algorithms-keeper algorithms-keeper bot added require type hints https://docs.python.org/3/library/typing.html and removed tests are failing Do not merge until tests pass labels May 29, 2024
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.

Anything like int(None) is going to cause a loud error. """


def bit_get(bint: int, index: int):

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: bit_get. If the function does not return a value, please provide the type hint as: def function() -> None:

return multibit_get(bint, index, 1)


def bit_set(bint: int, index: int, value: int = 1):

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: bit_set. If the function does not return a value, please provide the type hint as: def function() -> None:

return multibit_set(bint, index, 1, value)


def bit_insert(bint: int, index: int, value: int = 1):

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: bit_insert. If the function does not return a value, please provide the type hint as: def function() -> None:

billbreit and others added 2 commits May 29, 2024 11:31
Add type hints and fix leading spaces issues.
@algorithms-keeper algorithms-keeper bot added tests are failing Do not merge until tests pass and removed tests are failing Do not merge until tests pass labels May 29, 2024
billbreit and others added 2 commits May 29, 2024 11:56
@algorithms-keeper algorithms-keeper bot added tests are failing Do not merge until tests pass and removed tests are failing Do not merge until tests pass labels May 29, 2024
billbreit and others added 2 commits May 29, 2024 12:16
Fixed int | None return hints, mypy error
billbreit and others added 3 commits May 30, 2024 08:09
Changed return type from None to Exceptions and fix doctests
Few typos, debugging advice
@algorithms-keeper algorithms-keeper bot added tests are failing Do not merge until tests pass and removed tests are failing Do not merge until tests pass labels May 31, 2024
@algorithms-keeper algorithms-keeper bot removed the require type hints https://docs.python.org/3/library/typing.html label May 31, 2024
billbreit and others added 2 commits June 1, 2024 12:47
Better comments, errors, check bit_length=0 conditions
@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label Jun 1, 2024
Revert to old
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.

@@ -0,0 +1,255 @@
"""Bit integer manipulation, both single bit and multi-bit list-like

Choose a reason for hiding this comment

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

An error occurred while parsing the file: bit_manipulation/multibit_manipulation.py

Traceback (most recent call last):
  File "/opt/render/project/src/algorithms_keeper/parser/python_parser.py", line 146, in parse
    reports = lint_file(
              ^^^^^^^^^^
libcst._exceptions.ParserSyntaxError: Syntax Error @ 1:1.
tokenizer error: inconsistent mixing of tabs and spaces

"""Bit integer manipulation, both single bit and multi-bit list-like
^

@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label Jun 1, 2024
Coming down to the finish ...
@billbreit
Copy link
Author

I think I have multibit-manipulation.py debugged and ready for review. Do you have any suggestions ? Does the module name really describe what it does ? Are the comments unclear or too long ?

All the parenthesis in the multi-bit functions are complicated, but they run measurably faster on a Raspberry Pi Pico as a single statement. No garbage collection of course ( especially in 264K ), but Python seems to optimize these constructions beyond just saving memory and reference scavenging. After working with them, I find them readable in a straightforward left-right manner. Kind of harking back to the bit buffers of yesteryear, except they implemented it with hardware.

I had a problem with Ruff on my client workstation. There were many validation it didn't check. Is there a TOML configuration file I can use to match my Ruff to yours ?

  • Bill

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reviews This PR is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants