Difference between revisions of "ListReverse"

From Second Life Wiki
Jump to navigation Jump to search
(moved from user space to it's own page)
 
m (<lsl> tag to <source>)
 
Line 12: Line 12:
* MONO: 512 Bytes
* MONO: 512 Bytes
<!-- please replace with a similarly licensed version only -->
<!-- please replace with a similarly licensed version only -->
<lsl>list uListReverse( list vLstSrc ){
<source lang="lsl2">list uListReverse( list vLstSrc ){
     integer vIntCnt = (vLstSrc != []);
     integer vIntCnt = (vLstSrc != []);
     while (vIntCnt){
     while (vIntCnt){
Line 24: Line 24:
/*//  2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ]  //*/
/*//  2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ]  //*/
/*//  Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ]  //*/
/*//  Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ]  //*/
/*//--                                                                --//*/</lsl>
/*//--                                                                --//*/</source>


'''Faster Code:'''
'''Faster Code:'''
Line 30: Line 30:
* MONO: 512 Bytes
* MONO: 512 Bytes
<!-- please replace with a similarly licensed version only -->
<!-- please replace with a similarly licensed version only -->
<lsl>list uListReverse( list vLstSrc ){
<source lang="lsl2">list uListReverse( list vLstSrc ){
     integer vIntCnt = (vLstSrc != []);
     integer vIntCnt = (vLstSrc != []);
     while (vIntCnt){
     while (vIntCnt){
Line 41: Line 41:
/*//  2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ]  //*/
/*//  2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ]  //*/
/*//  Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ]  //*/
/*//  Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ]  //*/
/*//--                                                                --//*/</lsl>
/*//--                                                                --//*/</source>
}}
}}



Latest revision as of 14:20, 22 January 2015

User-Defined Function: list uListReverse( list vLstSrc );

Returns a list that is vLstSrc with the elements in reverse order

  • vLstSrc: source list to reverse


Smaller Code:

  • LSO: 156 Bytes
  • MONO: 512 Bytes
list uListReverse( list vLstSrc ){
    integer vIntCnt = (vLstSrc != []);
    while (vIntCnt){
        vLstSrc += llList2List( vLstSrc, (vIntCnt = ~-vIntCnt), vIntCnt );
        vLstSrc = llDeleteSubList( vLstSrc, vIntCnt, vIntCnt );
    }
    return vLstSrc;
}
/*//--                       Anti-License Text                         --//*/
/*//     Contributed Freely to the Public Domain without limitation.     //*/
/*//   2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ]   //*/
/*//  Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ]  //*/
/*//--                                                                 --//*/

Faster Code:

  • LSO: 160 Bytes
  • MONO: 512 Bytes
list uListReverse( list vLstSrc ){
    integer vIntCnt = (vLstSrc != []);
    while (vIntCnt){
        vLstSrc += llList2List( vLstSrc, (vIntCnt = ~-vIntCnt), vIntCnt );
    }
    return llList2List( vLstSrc, (vLstSrc != []) >> 1, -1 );
}
/*//--                       Anti-License Text                         --//*/
/*//     Contributed Freely to the Public Domain without limitation.     //*/
/*//   2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ]   //*/
/*//  Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ]  //*/
/*//--                                                                 --//*/

Caveats

  • The "Faster" version doubles the list size internally, and is more likely to cause a stack/heap collision(script crash) with large lists and/or limited free memory

Notes