diff --git a/lslopt/lslbasefuncs.py b/lslopt/lslbasefuncs.py index a150545..0239490 100644 --- a/lslopt/lslbasefuncs.py +++ b/lslopt/lslbasefuncs.py @@ -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) diff --git a/unit_tests/expr.suite/list-funcs-7.lsl b/unit_tests/expr.suite/list-funcs-7.lsl new file mode 100644 index 0000000..fff867d --- /dev/null +++ b/unit_tests/expr.suite/list-funcs-7.lsl @@ -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) diff --git a/unit_tests/expr.suite/list-funcs-7.out b/unit_tests/expr.suite/list-funcs-7.out new file mode 100644 index 0000000..5d2a8fb --- /dev/null +++ b/unit_tests/expr.suite/list-funcs-7.out @@ -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" +] \ No newline at end of file