Skip to content

Commit

Permalink
renew project
Browse files Browse the repository at this point in the history
  • Loading branch information
linjing-lab committed Jun 26, 2023
1 parent 2cdbbd3 commit be2a263
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ By the way, I didn't complete all the iterative data types, in order to develop
- [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]`.
- [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]`.
- [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.
- [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`.

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

Expand Down
1 change: 1 addition & 0 deletions README_release.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
|v1.2.3|`pip install sortingx==1.2.3`|Add Verify Function to Solve Comparison of Equal||
|v1.3.0|`pip install sortingx==1.3.0`|Revamp Redundant Data Exchanging About Equal Elements||
|v1.3.1|`pip install sortingx==1.3.1`|Reduce Shallow Replication in Pre-operations during Runtime||
|v1.3.2|`pip install sortingx==1.3.2`|Shrink the Returns of Calling Intrinsic Function to Get Length||

</div>

Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
matplotlib>=3.2.0
polars>=0.14.26
setuptools>=18.0
typing_extensions>=3.10.0.2
python>=3.7
typing_extensions>=3.10.0.2
2 changes: 1 addition & 1 deletion sortingx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@

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

__version__ = '1.3.1'
__version__ = '1.3.2'

assert sys.version_info >= (3, 7, 0)
22 changes: 14 additions & 8 deletions sortingx/sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ def bubble(__iterable: Iterable[_T], key: Optional[Callable[[_T], SupportsRichCo
__iterable: List[_T] = convert(__iterable)
compare: List[_T] = generate(__iterable, key)
if compare and not verify(compare):
for i in range(len(__iterable) - 1):
length: int = len(__iterable)
for i in range(length - 1):
flag: bool = False # early stop by adding a bool value named flag
for j in range(len(__iterable) - i - 1):
for j in range(length - i - 1):
if (compare[j] < compare[j + 1] if reverse else compare[j] > compare[j+1]):
__iterable[j], __iterable[j + 1] = __iterable[j + 1], __iterable[j]
if key != None:
Expand All @@ -51,7 +52,8 @@ def insert(__iterable: Iterable[_T], key: Optional[Callable[[_T], SupportsRichCo
__iterable: List[_T] = convert(__iterable)
compare: List[_T] = generate(__iterable, key)
if compare and not verify(compare):
for index in range(1, len(__iterable)):
length: int = len(__iterable)
for index in range(1, length):
keyc: _T = compare[index]
keya: _T = __iterable[index]
low : int = 0
Expand Down Expand Up @@ -175,7 +177,8 @@ def partition(l: int, r: int) -> int:
compare[index + 1], compare[r] = compare[r], compare[index + 1]
return index + 1
if compare and not verify(compare):
solve(0, len(__iterable) - 1)
length: int = len(__iterable)
solve(0, length - 1)
return __iterable

def merge(__iterable: Iterable[_T], key: Optional[Callable[[_T], SupportsRichComparison]]=None, reverse: bool=False) -> List[_T]:
Expand All @@ -195,14 +198,16 @@ def merg(low: int, mid: int, high: int) -> None:
:param high: The high cursor of __iterable (int).
'''
left: List[_T] = __iterable[low: mid]
lnl: int = len(left)
lc: List[_T] = compare[low: mid]
right: List[_T] = __iterable[mid: high]
lnr: int = len(right)
rc: List[_T] = compare[mid: high]
i: int = 0
j: int = 0
result: List[_T] = []
store: List[_T] = []
while i < len(left) and j < len(right):
while i < lnl and j < lnr:
if (rc[j] <= lc[i] if reverse else rc[j] >= lc[i]):
result.append(left[i])
store.append(lc[i])
Expand All @@ -223,11 +228,12 @@ def solve() -> None:
main
'''
i: int = 1
while i < len(__iterable):
length: int = len(__iterable)
while i < length:
low: int = 0
while low < len(__iterable):
while low < length:
mid: int = low + i
high: int = min(low + 2 * i, len(__iterable))
high: int = min(low + 2 * i, length)
if mid < high:
merg(low, mid, high)
low += 2 * i
Expand Down

0 comments on commit be2a263

Please sign in to comment.