Skip to content

Commit f8a933e

Browse files
committed
upgrade project
1 parent 2dc232f commit f8a933e

File tree

6 files changed

+51
-24
lines changed

6 files changed

+51
-24
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ explain:
9595

9696
By the way, I didn't complete all the iterative data types, in order to develop a more targeted scenario. If you are **interested** in other iterative data types, please add them in the `convert` function of the `_utils.py` file, for example: bytes, bytearray, range, zip. If you need to deal with `dict_keys`, `dict_values`, `dict_items`, please use `list()` to convert the variables of these data types before using any method of sortingx.
9797

98+
- [sortingx-1.2.2](https://github.com/linjing-lab/sorting-algorithms/tree/v1.2.2) is the package that support `range`, `zip`, `dict_keys`, `dict_values`, `dict_items` additionally, you can choose what suitable data you want to input.
99+
98100
## LICENSE
99101

100102
[Apache 2.0](./LICENSE)

README_release.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
|v1.1.3|`pip install sortingx==1.1.3`|Typing Check with More Local Variables||
1111
|v1.2.0|`pip install sortingx==1.2.0`|Optimize Generate Function's Kernel||
1212
|v1.2.1|`pip install sortingx==1.2.1`|Delete Core Function to Make Builtin First||
13+
|v1.2.2|`pip install sortingx==1.2.2`|Change Convert Function to Make it More Robust||
1314

1415
</div>

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
'Programming Language :: Python :: 3.8',
6363
'Programming Language :: Python :: 3.9',
6464
'Programming Language :: Python :: 3.10',
65+
'Programming Language :: Python :: 3.11',
6566
'License :: OSI Approved :: Apache Software License',
6667
'Topic :: Software Development',
6768
'Topic :: Software Development :: Libraries',

sortingx/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
import sys
1616

17-
from .sorting import bubble, insert, shell, heap, quick, merge
17+
from .sorting import bubble, insert, shell, heap, quick, merge, __all__
1818

19-
__version__ = '1.2.1'
19+
__version__ = '1.2.2'
2020

2121
assert sys.version_info >= (3, 7, 0)

sortingx/_utils.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,22 @@
1616

1717
# Data Generated by Mapping.
1818
def generate(__iterable: List[_T], key: Optional[Callable[[_T], SupportsRichComparison]]=None) -> List[_T]:
19+
'''
20+
:param __iterable: iterable data, mainly refers to `list`, `tuple`, `set`, `dict`, `str`, `zip`, `range`.
21+
:param key: callable function, for example: key=lambda x: x[1], key=lambda x: (x[0], x[1]), key=str.lower.
22+
23+
:return: data generated by map.
24+
'''
1925
compare: List[_T] = list(map(key, __iterable)) if key != None else __iterable
2026
return compare
2127

2228
# Uniformly Convert `Iterable` into `List`: Facilitate the Execution of Sorting Algorithms.
2329
def convert(__iterable: Iterable[_T]) -> List[_T]:
24-
if isinstance(__iterable, (tuple, str, set, dict)): # more iterable data: bytes, bytearray, range, zip, not support dict_keys, dict_values, dict_items.
25-
return list(__iterable)
26-
return __iterable
30+
'''
31+
:param __iterable: iterable data, mainly refers to `list`, `tuple`, `set`, `dict`, `str`, `zip`, `range`.
32+
33+
:return: converted result in a list.
34+
'''
35+
if isinstance(__iterable, list): # represents unifying data as list, not refer to allowing some input that is not suitable for sorting.
36+
return __iterable
37+
return list(__iterable) # iterable data (except list) are convert to list.

sortingx/sorting.py

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@
1515
from ._utils import generate, convert
1616
from ._typing import Iterable, Callable, Optional, _T, SupportsRichComparison, List
1717

18+
__all__ = ["bubble", "insert", "shell", "heap", "quick", "merge"]
19+
1820
def bubble(__iterable: Iterable[_T], key: Optional[Callable[[_T], SupportsRichComparison]]=None, reverse: bool=False) -> List[_T]:
1921
'''
20-
:param __iterable: iterable data.
21-
:param key: callable function, for example: key=lambda x: x[1], key=lambda x: (x[0], x[1]).
22+
:param __iterable: iterable data, mainly refers to `list`, `tuple`, `set`, `dict`, `str`, `zip`, `range`.
23+
:param key: callable function, for example: key=lambda x: x[1], key=lambda x: (x[0], x[1]), key=str.lower.
2224
:param reverse: whether to use descending order. The default is ascending order.
25+
26+
:return: bubble's sorted result in a list.
2327
'''
2428
__iterable: List[_T] = convert(__iterable)
2529
compare: List[_T] = generate(__iterable, key)
@@ -28,18 +32,20 @@ def bubble(__iterable: Iterable[_T], key: Optional[Callable[[_T], SupportsRichCo
2832
for j in range(len(__iterable) - i - 1):
2933
if (compare[j] < compare[j + 1] if reverse else compare[j] > compare[j+1]):
3034
__iterable[j], __iterable[j + 1] = __iterable[j + 1], __iterable[j]
31-
flag: bool = True
3235
if key != None:
3336
compare[j], compare[j + 1] = compare[j + 1], compare[j]
37+
flag: bool = True
3438
if not flag:
3539
break
3640
return __iterable
3741

3842
def insert(__iterable: Iterable[_T], key: Optional[Callable[[_T], SupportsRichComparison]]=None, reverse: bool=False) -> List[_T]:
3943
'''
40-
:param __iterable: iterable data.
41-
:param key: callable function, for example: key=lambda x: x[1], key=lambda x: (x[0], x[1]).
44+
:param __iterable: iterable data, mainly refers to `list`, `tuple`, `set`, `dict`, `str`, `zip`, `range`.
45+
:param key: callable function, for example: key=lambda x: x[1], key=lambda x: (x[0], x[1]), key=str.lower.
4246
:param reverse: whether to use descending order. The default is ascending order.
47+
48+
:return: insert's sorted result in a list.
4349
'''
4450
__iterable: List[_T] = convert(__iterable)
4551
compare: List[_T] = generate(__iterable, key)
@@ -65,9 +71,11 @@ def insert(__iterable: Iterable[_T], key: Optional[Callable[[_T], SupportsRichCo
6571

6672
def shell(__iterable: Iterable[_T], key: Optional[Callable[[_T], SupportsRichComparison]]=None, reverse: bool=False) -> List[_T]:
6773
'''
68-
:param __iterable: iterable data.
69-
:param key: callable function, for example: key=lambda x: x[1], key=lambda x: (x[0], x[1]).
74+
:param __iterable: iterable data, mainly refers to `list`, `tuple`, `set`, `dict`, `str`, `zip`, `range`.
75+
:param key: callable function, for example: key=lambda x: x[1], key=lambda x: (x[0], x[1]), key=str.lower.
7076
:param reverse: whether to use descending order. The default is ascending order.
77+
78+
:return: shell's sorted result in a list.
7179
'''
7280
__iterable: List[_T] = convert(__iterable)
7381
compare: List[_T] = generate(__iterable, key)
@@ -88,9 +96,11 @@ def shell(__iterable: Iterable[_T], key: Optional[Callable[[_T], SupportsRichCom
8896

8997
def heap(__iterable: Iterable[_T], key: Optional[Callable[[_T], SupportsRichComparison]]=None, reverse: bool=False) -> List[_T]:
9098
'''
91-
:param __iterable: iterable data.
92-
:param key: callable function, for example: key=lambda x: x[1], key=lambda x: (x[0], x[1]).
99+
:param __iterable: iterable data, mainly refers to `list`, `tuple`, `set`, `dict`, `str`, `zip`, `range`.
100+
:param key: callable function, for example: key=lambda x: x[1], key=lambda x: (x[0], x[1]), key=str.lower.
93101
:param reverse: whether to use descending order. The default is ascending order.
102+
103+
:return: heap's sorted result in a list.
94104
'''
95105
__iterable: List[_T] = convert(__iterable)
96106
compare: List[_T] = generate(__iterable, key)
@@ -124,9 +134,11 @@ def build(root: int, end: int) -> None:
124134

125135
def quick(__iterable: Iterable[_T], key: Optional[Callable[[_T], SupportsRichComparison]]=None, reverse: bool=False) -> List[_T]:
126136
'''
127-
:param __iterable: iterable data.
128-
:param key: callable function, for example: key=lambda x: x[1], key=lambda x: (x[0], x[1]).
137+
:param __iterable: iterable data, mainly refers to `list`, `tuple`, `set`, `dict`, `str`, `zip`, `range`.
138+
:param key: callable function, for example: key=lambda x: x[1], key=lambda x: (x[0], x[1]), key=str.lower.
129139
:param reverse: whether to use descending order. The default is ascending order.
140+
141+
:return: quick's sorted result in a list.
130142
'''
131143
__iterable: List[_T] = convert(__iterable)
132144
compare: List[_T] = generate(__iterable, key)
@@ -161,17 +173,19 @@ def partition(l: int, r: int) -> int:
161173

162174
def merge(__iterable: Iterable[_T], key: Optional[Callable[[_T], SupportsRichComparison]]=None, reverse: bool=False) -> List[_T]:
163175
'''
164-
:param __iterable: iterable data.
165-
:param key: callable function, for example: key=lambda x: x[1], key=lambda x: (x[0], x[1]).
176+
:param __iterable: iterable data, mainly refers to `list`, `tuple`, `set`, `dict`, `str`, `zip`, `range`.
177+
:param key: callable function, for example: key=lambda x: x[1], key=lambda x: (x[0], x[1]), key=str.lower.
166178
:param reverse: whether to use descending order. The default is ascending order.
179+
180+
:return: merge's sorted result in a list.
167181
'''
168182
__iterable: List[_T] = convert(__iterable)
169183
compare: List[_T] = generate(__iterable, key)
170184
def merg(low: int, mid: int, high: int) -> None:
171185
'''
172-
:param low: The low-side cursor of __iterable (int).
173-
:param mid: The middle-side cursor of __iterable (int).
174-
:param high: The high-side cursor of __iterable (int).
186+
:param low: The low cursor of __iterable (int).
187+
:param mid: The middle cursor of __iterable (int).
188+
:param high: The high cursor of __iterable (int).
175189
'''
176190
left: List[_T] = __iterable[low: mid]
177191
lc: List[_T] = compare[low: mid]
@@ -212,6 +226,4 @@ def solve() -> None:
212226
low += 2 * i
213227
i *= 2
214228
solve()
215-
return __iterable
216-
217-
__all__ = [bubble, insert, shell, heap, quick, merge]
229+
return __iterable

0 commit comments

Comments
 (0)