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:
Sei Lisa 2024-04-19 15:22:35 +02:00
parent 5ee290deff
commit ff85a1e837
3 changed files with 71 additions and 8 deletions

View file

@ -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)

View 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)

View 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"
]