mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2024-11-21 06:15:56 -07:00
Implement llListSortStrided
The only difference between this function and llListSort is the index, so llListSort is adapted to accept it.
This commit is contained in:
parent
5ee290deff
commit
ff85a1e837
3 changed files with 71 additions and 8 deletions
|
@ -1663,19 +1663,24 @@ def llListReplaceList(lst, elems, start, end):
|
|||
if end == -1: end += L
|
||||
return lst[:start] + elems + lst[end+1:]
|
||||
|
||||
def llListSort(lst, stride, asc):
|
||||
def llListSort(lst, stride, asc, idx=0):
|
||||
lst = fl(lst)
|
||||
stride = fi(stride)
|
||||
asc = fi(asc)
|
||||
lst = lst[:] # make a copy
|
||||
L = len(lst)
|
||||
broken = u'\ufb1a' > u'\U0001d41a' # that happens on Windows
|
||||
if stride < 1: stride = 1
|
||||
if stride < 1:
|
||||
stride = 1
|
||||
if L % stride:
|
||||
return lst
|
||||
if idx < 0:
|
||||
idx += stride
|
||||
if not (0 <= idx < stride):
|
||||
return []
|
||||
for i in xrange(0, L-stride, stride):
|
||||
# Optimized by caching the element in the outer loop AND after swapping.
|
||||
a = lst[i]
|
||||
a = lst[i+idx]
|
||||
ta = type(a)
|
||||
if ta == Vector:
|
||||
a = v2f(a) # list should contain vectors made only of floats
|
||||
|
@ -1688,7 +1693,7 @@ def llListSort(lst, stride, asc):
|
|||
# It should be OK because only equal types are compared.
|
||||
a = a.encode('utf-32-be') # pragma: no cover
|
||||
for j in xrange(i+stride, L, stride):
|
||||
b = lst[j]
|
||||
b = lst[j+idx]
|
||||
tb = type(b)
|
||||
gt = False
|
||||
if ta == tb:
|
||||
|
@ -1717,11 +1722,8 @@ def llListSort(lst, stride, asc):
|
|||
return lst
|
||||
|
||||
def llListSortStrided(src, stride, idx, ascending):
|
||||
src = fl(src)
|
||||
stride = fi(stride)
|
||||
idx = fi(idx)
|
||||
ascending = fi(ascending)
|
||||
raise ELSLCantCompute # TODO: Implement llListSortStrided
|
||||
return llListSort(src, stride, ascending, idx)
|
||||
|
||||
def llListStatistics(op, lst):
|
||||
op = fi(op)
|
||||
|
|
9
unit_tests/expr.suite/list-funcs-7.lsl
Normal file
9
unit_tests/expr.suite/list-funcs-7.lsl
Normal file
|
@ -0,0 +1,9 @@
|
|||
"T1" + llListSortStrided(["a", "á", "B", "C", "d", "e"], 1, 0, TRUE)
|
||||
+ "T2" + llListSortStrided([1, "C", 3, "A", 2, "B"], 1, 0, TRUE)
|
||||
+ "T3" + llListSortStrided([1, 3, 2, "C", "A", "B"], 1, 0, TRUE)
|
||||
+ "T4" + llListSortStrided([1, "C", 3, "A", 2, "B"], 2, 0, TRUE)
|
||||
+ "T5" + llListSortStrided([1, "C", 3, "A", 2, "B"], 2, 1, TRUE)
|
||||
+ "T6" + llListSortStrided([1, "C", 3, "A", 2, "B"], 2, 2, TRUE)
|
||||
+ "T7" + llListSortStrided([1, "C", 3, "A", 2, "B"], 2, -3, TRUE)
|
||||
+ "T8" + llListSortStrided([1, "C", 3, "A", 2, "B"], 2, -2, TRUE)
|
||||
+ "T9" + llListSortStrided([1, "C", 3, "A", 2, "B"], 2, -1, TRUE)
|
52
unit_tests/expr.suite/list-funcs-7.out
Normal file
52
unit_tests/expr.suite/list-funcs-7.out
Normal file
|
@ -0,0 +1,52 @@
|
|||
[ "T1"
|
||||
, "B"
|
||||
, "C"
|
||||
, "a"
|
||||
, "d"
|
||||
, "e"
|
||||
, "á"
|
||||
, "T2"
|
||||
, 1
|
||||
, "A"
|
||||
, 2
|
||||
, "B"
|
||||
, 3
|
||||
, "C"
|
||||
, "T3"
|
||||
, 1
|
||||
, 2
|
||||
, 3
|
||||
, "A"
|
||||
, "B"
|
||||
, "C"
|
||||
, "T4"
|
||||
, 1
|
||||
, "C"
|
||||
, 2
|
||||
, "B"
|
||||
, 3
|
||||
, "A"
|
||||
, "T5"
|
||||
, 3
|
||||
, "A"
|
||||
, 2
|
||||
, "B"
|
||||
, 1
|
||||
, "C"
|
||||
, "T6"
|
||||
, "T7"
|
||||
, "T8"
|
||||
, 1
|
||||
, "C"
|
||||
, 2
|
||||
, "B"
|
||||
, 3
|
||||
, "A"
|
||||
, "T9"
|
||||
, 3
|
||||
, "A"
|
||||
, 2
|
||||
, "B"
|
||||
, 1
|
||||
, "C"
|
||||
]
|
Loading…
Reference in a new issue