OsListSortInPlace
From OpenSimulator
(One intermediate revision by one user not shown) | |||
Line 10: | Line 10: | ||
- Does nothing if the list length is not a multiple of stride.<br> | - Does nothing if the list length is not a multiple of stride.<br> | ||
- The sort considers the elements that are at indexes that are multiple of stride. The other elements between those multiples are just copied around.<br> | - The sort considers the elements that are at indexes that are multiple of stride. The other elements between those multiples are just copied around.<br> | ||
− | i.e. if the element at [n * stride] is moved to [m * stride], elements [n * stride + i] are moved to [m * stride + i] for i = 1 to stride -1 (n m and i integers).<br> | + | i.e. if the element at [n * stride] is moved to [m * stride], elements [n * stride + i] are moved to [m * stride + i] for i = 1 to stride -1 (n, m and i integers).<br> |
− | - if there are different object types (ie some are integer, others string, etc) at the consider indexes [n * stride], each type is considered as a sub list and each list is sorted.<br> | + | - if there are different object types (ie some are integer, others string, etc) at the consider indexes [n * stride], each type is considered as a sub list and each sub list is sorted.<br> |
[1,"D",-4,"A","B"] will be [-4,"A",1,"B","D"], in ascending sort and stride 1.<br> | [1,"D",-4,"A","B"] will be [-4,"A",1,"B","D"], in ascending sort and stride 1.<br> | ||
- Lists with stride 1 and elements all of same type are a lot faster to sort than others, because in that case faster algorithms can be used.<br> | - Lists with stride 1 and elements all of same type are a lot faster to sort than others, because in that case faster algorithms can be used.<br> | ||
Line 26: | Line 26: | ||
osListSortInPlace(src, 1, TRUE); | osListSortInPlace(src, 1, TRUE); | ||
llSay(0, "sorted in ascending order with stride 1: " + llDumpList2String(src,",")); | llSay(0, "sorted in ascending order with stride 1: " + llDumpList2String(src,",")); | ||
+ | |||
+ | src = [1,"D",-4,"A",0,"B"]; | ||
+ | llSay(0, "original list: " + llDumpList2String(src,",")); | ||
+ | osListSortInPlace(src, 2, 1); | ||
+ | llSay(0, "sorted in ascending order with stride 2: " + llDumpList2String(src,",")); | ||
} | } | ||
} | } |
Latest revision as of 17:26, 1 June 2021
osListSortInPlace(list src, integer stride, integer ascending)
| |
Identical to llListSort but does the sort on the original list, so using less memory.
- Does nothing if the list length is not a multiple of stride. | |
Threat Level | This function does not do a threat level check |
Permissions | Use of this function is always allowed by default |
Extra Delay | 0 seconds |
Example(s) | |
// default { state_entry() { llSay(0, "osListSortInPlace example"); list src = [1,"D",-4,"A","B"]; llSay(0, "original list: " + llDumpList2String(src,",")); osListSortInPlace(src, 1, TRUE); llSay(0, "sorted in ascending order with stride 1: " + llDumpList2String(src,",")); src = [1,"D",-4,"A",0,"B"]; llSay(0, "original list: " + llDumpList2String(src,",")); osListSortInPlace(src, 2, 1); llSay(0, "sorted in ascending order with stride 2: " + llDumpList2String(src,",")); } } | |
Notes | |
This function was added in 0.9.2 |