ListReverse

From Second Life Wiki
Revision as of 03:38, 29 May 2010 by Void Singer (talk | contribs) (moved from user space to it's own page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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

<lsl>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 ] //*/ /*//-- --//*/</lsl>

Faster Code:

  • LSO: 160 Bytes
  • MONO: 512 Bytes

<lsl>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 ] //*/

/*//-- --//*/</lsl>

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