Difference between revisions of "LlListSort"

From Second Life Wiki
Jump to navigation Jump to search
m (spelling: to affected from effected, to descending from desending, to ascending from assending, also mention slowness of bubble sort more prominently)
Line 4: Line 4:
|p1_type=list|p1_name=src|p1_desc=List to be sorted.
|p1_type=list|p1_name=src|p1_desc=List to be sorted.
|p2_type=integer|p2_name=stride|p2_desc=number of entries per stride, if less then 1 it is assumed to be 1.
|p2_type=integer|p2_name=stride|p2_desc=number of entries per stride, if less then 1 it is assumed to be 1.
|p3_type=integer|p3_name=ascending|p3_desc=if {{LSLG|FALSE}} then the sort order is desending, otherwise the order is assending.
|p3_type=integer|p3_name=ascending|p3_desc=if {{LSLG|FALSE}} then the sort order is descending, otherwise the order is ascending.
|func_footnote
|func_footnote
|func_desc
|func_desc
|return_text=that is '''src''' sorted by '''stride'''.
|return_text=that is '''src''' sorted by '''stride'''.
|spec=A bubble sort is employed to perform the sort.<br/>
|spec=A slow bubble sort is employed to perform the sort.<br/>
The sort order is effected by type.<br/>
The sort order is affected by type.<br/>
Each type is sorted individually and then feathered to have the same order of types.
Each type is sorted individually and then feathered to have the same order of types.
<pre>llListSort([1, "C", 3, "A", 2, "B"], 1, TRUE) == [1, "A", 2, "B", 3, "C"]
<pre>llListSort([1, "C", 3, "A", 2, "B"], 1, TRUE) == [1, "A", 2, "B", 3, "C"]

Revision as of 15:56, 22 October 2007

Summary

Function: list llListSort( list src, integer stride, integer ascending );

Returns a list that is src sorted by stride.

• list src List to be sorted.
• integer stride number of entries per stride, if less then 1 it is assumed to be 1.
• integer ascending if FALSE then the sort order is descending, otherwise the order is ascending.

Specification

A slow bubble sort is employed to perform the sort.
The sort order is affected by type.
Each type is sorted individually and then feathered to have the same order of types.

llListSort([1, "C", 3, "A", 2, "B"], 1, TRUE) == [1, "A", 2, "B", 3, "C"]
llListSort([1, 3, 2, "C", "A", "B"], 1, TRUE) == [1, 2, 3, "A", "B", "C"]

llListSort([1, "C", 3, "A", 2, "B"], 2, TRUE) == [1, "C", 2, "B", 3, "A"]

Caveats

A bubble sort is a sorting algorithm with a Big O of N*N. Why Linden Labs did not use a N*log(N) sorting algorithm such as Heap Sort or Merge Sort is unkown...

All Issues ~ Search JIRA for related Bugs

Examples

list numbers = [3, "three", 2, "two", 1, "one"];
default
{
    state_entry()
    {
        llOwnerSay(llDumpList2String(numbers, ","));
        // Object: 3,three,2,two,1,one
        numbers = llListSort(numbers, 2, TRUE);
        llOwnerSay(llDumpList2String(numbers, ","));
        // Object: 1,one,2,two,3,three
    }
}

Deep Notes

Search JIRA for related Issues

Source

lsa_bubble_sort(): 'linden\indra\lscript\lscript_alloc.h'

Signature

function list llListSort( list src, integer stride, integer ascending );