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
9 changes: 7 additions & 2 deletions sorts/benchmark_sorts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

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
Expand All @@ -37,8 +37,13 @@
from sorts.shell_sort import shell_sort
from sorts.tim_sort import tim_sort


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