Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions sorts/benchmark_sorts.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,28 @@
re-implements a sort.
"""

import random
import sys
from collections.abc import Callable, Sequence
from collections.abc import Sequence
from itertools import pairwise
from timeit import timeit
from typing import Protocol

from sorts.bubble_sort import bubble_sort_iterative
from sorts.cocktail_shaker_sort import cocktail_shaker_sort
from sorts.comb_sort import comb_sort
from sorts.gnome_sort import gnome_sort
from sorts.heap_sort import heap_sort
from sorts.insertion_sort import insertion_sort
from sorts.merge_sort import merge_sort
from sorts.quick_sort import quick_sort
from sorts.selection_sort import selection_sort
from sorts.shell_sort import shell_sort
from sorts.tim_sort import tim_sort

Check failure on line 38 in sorts/benchmark_sorts.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (I001)

sorts/benchmark_sorts.py:21:1: I001 Import block is un-sorted or un-formatted help: Organize imports

Check failure on line 38 in sorts/benchmark_sorts.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (I001)

sorts/benchmark_sorts.py:21:1: I001 Import block is un-sorted or un-formatted help: Organize imports

Check failure on line 38 in sorts/benchmark_sorts.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (I001)

sorts/benchmark_sorts.py:21:1: I001 Import block is un-sorted or un-formatted help: Organize imports

class SortFunction(Protocol):
def __call__[T](self, collection: list[T], /) -> Sequence[T]: ...
# name -> callable. Every callable accepts a list and returns the sorted list.
SORTS: dict[str, Callable[[list[int]], Sequence[int]]] = {
SORTS: dict[str, SortFunction] = {
"bubble_sort": bubble_sort_iterative,
"cocktail_shaker_sort": cocktail_shaker_sort,
"comb_sort": comb_sort,
Expand Down
Loading