Skip to content

Commit ed38bab

Browse files
committed
renew project
1 parent a994e67 commit ed38bab

File tree

5 files changed

+11
-25
lines changed

5 files changed

+11
-25
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ explain:
9191
- sortingx-1.1.2 is the first stable version that has a return value and extends the iterable data types.
9292
- sortingx-1.1.3 is the version that complete the typing of local variables and align with `sorted()` usage method.
9393
- sortingx-1.2.0 is the end version of sorting series, which optimize the kernel of generate.
94+
- sortingx-1.2.1 is the portable version that comparison is faster than ever, the generate is more portable.
9495

9596
## LICENSE
9697

Diff for: README_release.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
|v1.1.2|`pip install sortingx==1.1.2`|Support More Iterative Data Types||
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||
12+
|v1.2.1|`pip install sortingx==1.2.1`|Delete Core Function to Make Builtin First||
1213

1314
</div>

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
1818

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

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

Diff for: sortingx/_utils.py

-16
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,8 @@
1717
# Data Generated by Mapping.
1818
def generate(__iterable: List[_T], key: Optional[Callable[[_T], SupportsRichComparison]]=None) -> List[_T]:
1919
compare: List[_T] = list(map(key, __iterable)) if key != None else __iterable
20-
compare: List[_T] = ([[value] for value in compare] if (compare and not isinstance(compare[0], (list, tuple))) else compare) if key != None else __iterable
2120
return compare
2221

23-
# Redefined Comparison Rules: A High-Speed State Selection Function.
24-
def core(left: List[_T], right: List[_T], key: Optional[Callable[[_T], SupportsRichComparison]]=None, reverse: bool=False) -> bool:
25-
if key == None:
26-
return left < right if reverse else left > right
27-
for index in range(0, len(left)):
28-
if left[index] > right[index] and reverse:
29-
return False
30-
elif left[index] > right[index] and not reverse:
31-
return True
32-
elif left[index] < right[index] and reverse:
33-
return True
34-
elif left[index] < right[index] and not reverse:
35-
return False
36-
return False # Reduce the Times of Data Exchanging.
37-
3822
# Uniformly Convert `Iterable` into `List`: Facilitate the Execution of Sorting Algorithms.
3923
def convert(__iterable: Iterable[_T]) -> List[_T]:
4024
if isinstance(__iterable, (tuple, str, set, dict)):

Diff for: sortingx/sorting.py

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

15-
from ._utils import core, generate, convert
15+
from ._utils import generate, convert
1616
from ._typing import Iterable, Callable, Optional, _T, SupportsRichComparison, List
1717

1818
def bubble(__iterable: Iterable[_T], key: Optional[Callable[[_T], SupportsRichComparison]]=None, reverse: bool=False) -> List[_T]:
@@ -26,7 +26,7 @@ def bubble(__iterable: Iterable[_T], key: Optional[Callable[[_T], SupportsRichCo
2626
for i in range(len(__iterable) - 1):
2727
flag: bool = False # early stop by adding a bool value named flag
2828
for j in range(len(__iterable) - i - 1):
29-
if core(compare[j], compare[j + 1], key, reverse):
29+
if (compare[j] < compare[j + 1] if reverse else compare[j] > compare[j+1]):
3030
__iterable[j], __iterable[j + 1] = __iterable[j + 1], __iterable[j]
3131
flag: bool = True
3232
if key != None:
@@ -50,7 +50,7 @@ def insert(__iterable: Iterable[_T], key: Optional[Callable[[_T], SupportsRichCo
5050
high: int = index - 1
5151
while low <= high: # sequence conforming to monotonicity
5252
mid: int = (low + high) // 2
53-
if core(keyc, compare[mid], key, reverse):
53+
if (keyc < compare[mid] if reverse else keyc > compare[mid]):
5454
low: int = mid + 1
5555
else:
5656
high: int = mid - 1
@@ -78,7 +78,7 @@ def shell(__iterable: Iterable[_T], key: Optional[Callable[[_T], SupportsRichCom
7878
while gap >= 1:
7979
for index in range(gap, length):
8080
next: int = index
81-
while next >= gap and core(compare[next - gap], compare[next], key, reverse):
81+
while next >= gap and (compare[next - gap] < compare[next] if reverse else compare[next - gap] > compare[next]):
8282
__iterable[next], __iterable[next - gap] = __iterable[next - gap], __iterable[next]
8383
if key != None:
8484
compare[next], compare[next - gap] = compare[next - gap], compare[next]
@@ -102,9 +102,9 @@ def build(root: int, end: int) -> None:
102102
piv: int = root
103103
left: int = 2 * root + 1
104104
right: int = 2 * root + 2
105-
if left < end and core(compare[left], compare[root], key, reverse):
105+
if left < end and (compare[left] < compare[root] if reverse else compare[left] > compare[root]):
106106
piv: int = left
107-
if right < end and core(compare[right], compare[piv], key, reverse):
107+
if right < end and (compare[right] < compare[piv] if reverse else compare[right] > compare[piv]):
108108
piv: int = right
109109
if piv != root:
110110
__iterable[root], __iterable[piv] = __iterable[piv], __iterable[root]
@@ -147,7 +147,7 @@ def partition(l: int, r: int) -> int:
147147
val: _T = compare[r]
148148
index: int = l - 1
149149
for ind in range(l, r):
150-
if core(val, compare[ind], key, reverse):
150+
if (val < compare[ind] if reverse else val > compare[ind]):
151151
index += 1
152152
__iterable[index], __iterable[ind] = __iterable[ind], __iterable[index]
153153
if key != None:
@@ -182,7 +182,7 @@ def merg(low: int, mid: int, high: int) -> None:
182182
result: List[_T] = []
183183
store: List[_T] = []
184184
while i < len(left) and j < len(right):
185-
if core(rc[j], lc[i], key, reverse):
185+
if (rc[j] < lc[i] if reverse else rc[j] > lc[i]):
186186
result.append(left[i])
187187
store.append(lc[i])
188188
i += 1

0 commit comments

Comments
 (0)