Add sorts/sleep_sort.py#13507
Conversation
Add `sort/sleep_sort.py`: a novelty sleep-sort implementation with a simulated mode (safe for CI) and an optional real threaded mode. ### Files added - sort/sleep_sort.py ### Notes - File name is snake_case. - Includes doctests; tested with `python -m doctest -v sort/sleep_sort.py`. - Follows repository style. If this addresses an issue, add: `Fixes #<issue-number>`
There was a problem hiding this comment.
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 reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto 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.
sorts/sleep_sort.py
Outdated
| import time | ||
|
|
||
|
|
||
| def sleep_sort(a: List[int], simulate: bool = True, scale: float = 0.01) -> None: |
There was a problem hiding this comment.
Please provide descriptive name for the parameter: a
| results: List[int] = [] | ||
| lock = threading.Lock() | ||
|
|
||
| def worker(value: int) -> None: |
There was a problem hiding this comment.
As there is no test file in this pull request nor any test function or class in the file sorts/sleep_sort.py, please provide doctest for the function worker
sorts/sleep_sort.py
Outdated
| a[:] = results | ||
|
|
||
|
|
||
| def main() -> None: |
There was a problem hiding this comment.
As there is no test file in this pull request nor any test function or class in the file sorts/sleep_sort.py, please provide doctest for the function main
Add sorts/sleep_sort.py: a novelty sleep-sort implementation with a simulated mode (safe for CI) and an optional real threaded mode. ### Files added - sorts/sleep_sort.py ### Notes - File name is snake_case. - Includes doctests; tested with python -m doctest -v sort/sleep_sort.py. - Follows repository style. If this addresses an issue, add: Fixes #<issue-number>
There was a problem hiding this comment.
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 reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto 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.
| results: List[int] = [] | ||
| lock = threading.Lock() | ||
|
|
||
| def worker(value: int) -> None: |
There was a problem hiding this comment.
As there is no test file in this pull request nor any test function or class in the file sorts/sleep_sort.py, please provide doctest for the function worker
Describe your change:
Added a new and quirky sorting algorithm called Sleep Sort to the
sortsdirectory.This algorithm works by spawning a separate thread for each number and using time delays to order the output.
While not practical, it is an interesting demonstration of concurrency and timing-based sorting.
The implementation includes type hints, proper docstrings, and doctests as required by the contributing guidelines.
Checklist: