Skip to content

Commit be2a263

Browse files
committed
renew project
1 parent 2cdbbd3 commit be2a263

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ By the way, I didn't complete all the iterative data types, in order to develop
9999
- [sortingx-1.2.3](https://github.com/linjing-lab/sorting-algorithms/tree/v1.2.3) is the package that corrected the situation where elements are equal in `compare`, support more input data, like data as `[['Jack', (98, 100)], ['Bob', (98, 99)], ['Jessi', (98, 97)]]` and key as `lambda x: x[1][0]`.
100100
- [sortingx-1.3.0](https://github.com/linjing-lab/sorting-algorithms/tree/v1.3.0) is the final version that fully aligned with the `sorted`', reduces redundant data exchanging. like data as `[('Alex', 97, 90, 98, 95), ('Jack', 97, 88, 98, 92), ('Peter', 92, 95, 92, 96), ('Li', 97, 89, 98, 92)]` and key as `key=lambda x: x[1]`.
101101
- [sortingx-1.3.1](https://github.com/linjing-lab/sorting-algorithms/tree/v1.3.1) is the improved version from v1.3.0, and pre-operations from `_utils` are more conise to reduce shallow copy in Runtime.
102+
- [sortingx-1.3.2](https://github.com/linjing-lab/sorting-algorithms/tree/v1.3.2) is the optimized version from v1.3.1, and shrink the returns of calling intrinsic function named `__len__` to get length of `__iterable`.
102103

103104
refer to [this](./README_release.md) for downloaded info.
104105

Diff for: README_release.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
|v1.2.3|`pip install sortingx==1.2.3`|Add Verify Function to Solve Comparison of Equal||
1515
|v1.3.0|`pip install sortingx==1.3.0`|Revamp Redundant Data Exchanging About Equal Elements||
1616
|v1.3.1|`pip install sortingx==1.3.1`|Reduce Shallow Replication in Pre-operations during Runtime||
17+
|v1.3.2|`pip install sortingx==1.3.2`|Shrink the Returns of Calling Intrinsic Function to Get Length||
1718

1819
</div>
1920

Diff for: requirements.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
matplotlib>=3.2.0
22
polars>=0.14.26
33
setuptools>=18.0
4-
typing_extensions>=3.10.0.2
5-
python>=3.7
4+
typing_extensions>=3.10.0.2

Diff for: sortingx/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616

1717
from .sorting import bubble, insert, shell, heap, quick, merge, __all__
1818

19-
__version__ = '1.3.1'
19+
__version__ = '1.3.2'
2020

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

Diff for: sortingx/sorting.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ def bubble(__iterable: Iterable[_T], key: Optional[Callable[[_T], SupportsRichCo
2828
__iterable: List[_T] = convert(__iterable)
2929
compare: List[_T] = generate(__iterable, key)
3030
if compare and not verify(compare):
31-
for i in range(len(__iterable) - 1):
31+
length: int = len(__iterable)
32+
for i in range(length - 1):
3233
flag: bool = False # early stop by adding a bool value named flag
33-
for j in range(len(__iterable) - i - 1):
34+
for j in range(length - i - 1):
3435
if (compare[j] < compare[j + 1] if reverse else compare[j] > compare[j+1]):
3536
__iterable[j], __iterable[j + 1] = __iterable[j + 1], __iterable[j]
3637
if key != None:
@@ -51,7 +52,8 @@ def insert(__iterable: Iterable[_T], key: Optional[Callable[[_T], SupportsRichCo
5152
__iterable: List[_T] = convert(__iterable)
5253
compare: List[_T] = generate(__iterable, key)
5354
if compare and not verify(compare):
54-
for index in range(1, len(__iterable)):
55+
length: int = len(__iterable)
56+
for index in range(1, length):
5557
keyc: _T = compare[index]
5658
keya: _T = __iterable[index]
5759
low : int = 0
@@ -175,7 +177,8 @@ def partition(l: int, r: int) -> int:
175177
compare[index + 1], compare[r] = compare[r], compare[index + 1]
176178
return index + 1
177179
if compare and not verify(compare):
178-
solve(0, len(__iterable) - 1)
180+
length: int = len(__iterable)
181+
solve(0, length - 1)
179182
return __iterable
180183

181184
def merge(__iterable: Iterable[_T], key: Optional[Callable[[_T], SupportsRichComparison]]=None, reverse: bool=False) -> List[_T]:
@@ -195,14 +198,16 @@ def merg(low: int, mid: int, high: int) -> None:
195198
:param high: The high cursor of __iterable (int).
196199
'''
197200
left: List[_T] = __iterable[low: mid]
201+
lnl: int = len(left)
198202
lc: List[_T] = compare[low: mid]
199203
right: List[_T] = __iterable[mid: high]
204+
lnr: int = len(right)
200205
rc: List[_T] = compare[mid: high]
201206
i: int = 0
202207
j: int = 0
203208
result: List[_T] = []
204209
store: List[_T] = []
205-
while i < len(left) and j < len(right):
210+
while i < lnl and j < lnr:
206211
if (rc[j] <= lc[i] if reverse else rc[j] >= lc[i]):
207212
result.append(left[i])
208213
store.append(lc[i])
@@ -223,11 +228,12 @@ def solve() -> None:
223228
main
224229
'''
225230
i: int = 1
226-
while i < len(__iterable):
231+
length: int = len(__iterable)
232+
while i < length:
227233
low: int = 0
228-
while low < len(__iterable):
234+
while low < length:
229235
mid: int = low + i
230-
high: int = min(low + 2 * i, len(__iterable))
236+
high: int = min(low + 2 * i, length)
231237
if mid < high:
232238
merg(low, mid, high)
233239
low += 2 * i

0 commit comments

Comments
 (0)