Skip to content

Commit 09336a1

Browse files
committed
renew project
1 parent d67d6c5 commit 09336a1

14 files changed

+10146
-125
lines changed

README_release.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
|edition|download|trait|check|
66
|--|--|--|--|
77
|v1.1.0|`pip install sortingx==1.1.0`|Write in Python with Typing||
8-
|v1.1.1|`pip install sortingx==1.1.1`|Accelerate with Numda, Complete Comparison Between Data||
8+
|v1.1.1|`pip install sortingx==1.1.1`|Accelerate with Numba, Complete Comparison Between Data||
99
|v2.0.0|`pip install sortingx==2.0.0`|Rely on Cython||
1010
|v3.0.0|`pip install sortingx==3.0.0`|Restuct with C++||
1111
|v4.0.0|`pip install sortingx==4.0.0`|Rust with PyO3||

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# TODO 规定项目运作依赖项及版本

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,5 @@
6767
'Topic :: Software Development :: Libraries',
6868
'Topic :: Software Development :: Libraries :: Python Modules',
6969
],
70+
# TODO 补全下载依赖项
7071
)

sortingx/_typing.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
# limitations under the License.
1414

1515
from typing import (
16+
Any,
1617
Iterable,
1718
Callable,
1819
Optional
19-
)
20+
)
21+
22+
from abc import _T # TODO 保证导入正确
23+
24+
SupportsRichComparison = Any # TODO 补全SupportRichComparison

sortingx/_utils.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from ._typing import Iterable, Callable, Optional
15+
from ._typing import Iterable, Callable, Optional, _T, SupportsRichComparison
1616

17-
def generate(array: Iterable, key: Optional[Callable]=None) -> list:
17+
def generate(array: Iterable[_T], key: Optional[Callable[[_T], SupportsRichComparison]]=None) -> list:
1818
compare = list(map(key, array)) if key != None else array
1919
compare = ([[value] for value in compare] if compare and compare[0] is not list else compare) if key != None else array
2020
return compare
2121

22-
def core(left: Iterable, right: Iterable, key: Optional[Callable]=None, reverse: bool=False) -> bool:
22+
def core(left: Iterable[_T], right: Iterable[_T], key: Optional[Callable[[_T], SupportsRichComparison]]=None, reverse: bool=False) -> bool:
2323
if key == None:
2424
return left < right if reverse else left > right
2525
for index in range(0, len(left)):

sortingx/sorting.py

+24-26
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
__all__ = ['bubble', 'insert', 'shell', 'heap', 'quick', 'merge']
16-
17-
from numba import jit
1815
from ._utils import core, generate
19-
from ._typing import Iterable, Callable, Optional
20-
21-
@jit(nopython=True)
22-
def bubble(array: Iterable, key: Optional[Callable]=None, reverse: bool=False) -> None:
16+
from ._typing import Iterable, Callable, Optional, _T, SupportsRichComparison
17+
# TODO 加速六种方法
18+
def bubble(array: Iterable[_T], key: Optional[Callable[[_T], SupportsRichComparison]]=None, reverse: bool=False) -> None:
2319
'''
24-
:param array: iterable data, support numeric data, such as mixing integer and floating point data; support all data of string type; mixing string and numeric types is not supported on the same column.
20+
:param array: iterable data.
2521
:param key: callable function, for example: key=lambda x: x[1], key=lambda x: (x[0], x[1]).
2622
:param reverse: whether to use descending order. The default is ascending order.
2723
'''
@@ -37,10 +33,9 @@ def bubble(array: Iterable, key: Optional[Callable]=None, reverse: bool=False) -
3733
if not flag:
3834
break
3935

40-
@jit(nopython=True)
41-
def insert(array: Iterable, key: Optional[Callable]=None, reverse: bool=False) -> None:
36+
def insert(array: Iterable[_T], key: Optional[Callable[[_T], SupportsRichComparison]]=None, reverse: bool=False) -> None:
4237
'''
43-
:param array: iterable data, support numeric data, such as mixing integer and floating point data; support all data of string type; mixing string and numeric types is not supported on the same column.
38+
:param array: iterable data.
4439
:param key: callable function, for example: key=lambda x: x[1], key=lambda x: (x[0], x[1]).
4540
:param reverse: whether to use descending order. The default is ascending order.
4641
'''
@@ -62,9 +57,9 @@ def insert(array: Iterable, key: Optional[Callable]=None, reverse: bool=False) -
6257
if key != None:
6358
compare[low] = keyc
6459

65-
def shell(array: Iterable, key: Optional[Callable]=None, reverse: bool=False) -> None:
60+
def shell(array: Iterable[_T], key: Optional[Callable[[_T], SupportsRichComparison]]=None, reverse: bool=False) -> None:
6661
'''
67-
:param array: iterable data, support numeric data, such as mixing integer and floating point data; support all data of string type; mixing string and numeric types is not supported on the same column.
62+
:param array: iterable data.
6863
:param key: callable function, for example: key=lambda x: x[1], key=lambda x: (x[0], x[1]).
6964
:param reverse: whether to use descending order. The default is ascending order.
7065
'''
@@ -83,17 +78,17 @@ def shell(array: Iterable, key: Optional[Callable]=None, reverse: bool=False) ->
8378
next -= gap
8479
gap = int(gap / 3)
8580

86-
@jit(nopython=True)
87-
def heap(array: Iterable, key: Optional[Callable]=None, reverse: bool=False) -> None:
81+
def heap(array: Iterable[_T], key: Optional[Callable[[_T], SupportsRichComparison]]=None, reverse: bool=False) -> None:
8882
'''
89-
:param array: iterable data, support numeric data, such as mixing integer and floating point data; support all data of string type; mixing string and numeric types is not supported on the same column.
83+
:param array: iterable data.
9084
:param key: callable function, for example: key=lambda x: x[1], key=lambda x: (x[0], x[1]).
9185
:param reverse: whether to use descending order. The default is ascending order.
9286
'''
9387
compare = generate(array, key)
9488
def build(root: int, end: int) -> None:
9589
'''
96-
Root: cursor indicating the root node (integer), end: cursor indicating the end of the array (integer)
90+
:param root: cursor indicating the root node (int).
91+
:param end: cursor indicating the end of the array (int).
9792
'''
9893
piv = root
9994
left = 2 * root + 1
@@ -117,10 +112,9 @@ def build(root: int, end: int) -> None:
117112
compare[0], compare[end] = compare[end], compare[0]
118113
build(0, end)
119114

120-
@jit(nopython=True)
121-
def quick(array: Iterable, key: Optional[Callable]=None, reverse: bool=False) -> None:
115+
def quick(array: Iterable[_T], key: Optional[Callable[[_T], SupportsRichComparison]]=None, reverse: bool=False) -> None:
122116
'''
123-
:param array: iterable data, support numeric data, such as mixing integer and floating point data; support all data of string type; mixing string and numeric types is not supported on the same column.
117+
:param array: iterable data.
124118
:param key: callable function, for example: key=lambda x: x[1], key=lambda x: (x[0], x[1]).
125119
:param reverse: whether to use descending order. The default is ascending order.
126120
'''
@@ -136,7 +130,8 @@ def solve(l: int, r: int) -> None:
136130

137131
def partition(l: int, r: int) -> int:
138132
'''
139-
l: The left cursor of array (integer), r: The right cursor of array (integer)
133+
:param l: The left cursor of array (int).
134+
:param r: The right cursor of array (int).
140135
'''
141136
val = compare[r]
142137
index = l - 1
@@ -152,17 +147,18 @@ def partition(l: int, r: int) -> int:
152147
return index + 1
153148
solve(0, len(array)-1)
154149

155-
@jit(nopython=True)
156-
def merge(array: Iterable, key: Callable=None, reverse: bool=False) -> None:
150+
def merge(array: Iterable[_T], key: Optional[Callable[[_T], SupportsRichComparison]]=None, reverse: bool=False) -> None:
157151
'''
158-
:param array: iterable data, support numeric data, such as mixing integer and floating point data; support all data of string type; mixing string and numeric types is not supported on the same column.
152+
:param array: iterable data.
159153
:param key: callable function, for example: key=lambda x: x[1], key=lambda x: (x[0], x[1]).
160154
:param reverse: whether to use descending order. The default is ascending order.
161155
'''
162156
compare = generate(array, key)
163157
def merge(low: int, mid: int, high: int) -> None:
164158
'''
165-
low: The low-side cursor of array (integer), mid: The middle-side cursor of array (integer), high: The high-side cursor of array (integer)
159+
:param low: The low-side cursor of array (int).
160+
:param mid: The middle-side cursor of array (int).
161+
:param high: The high-side cursor of array (int).
166162
'''
167163
left, lc = array[low: mid], compare[low: mid]
168164
right, rc = array[mid: high], compare[mid: high]
@@ -199,4 +195,6 @@ def solve() -> None:
199195
merge(low, mid, high)
200196
low += 2 * i
201197
i *= 2
202-
solve()
198+
solve()
199+
200+
__all__ = [bubble, insert, shell, heap, quick, merge]

tests/__init__.py

Whitespace-only changes.

tests/benchmark.ipynb

+84-87
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)