Difference between revisions of "ListFindListReverse"

From Second Life Wiki
Jump to navigation Jump to search
(new function)
 
m (<lsl> tag to <source>)
 
Line 15: Line 15:
* MONO: 512 Bytes
* MONO: 512 Bytes
<!-- please replace with a similarly licensed version only -->
<!-- please replace with a similarly licensed version only -->
<lsl>
<source lang="lsl2">
integer uListFindListReverse( list vLstSrc, list vLstTst ){
integer uListFindListReverse( list vLstSrc, list vLstTst ){
     integer vIntRtn;
     integer vIntRtn;
Line 28: Line 28:
/*//  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:18, 22 January 2015

User-Defined Function: integer uListFindListReverse( list vLstSrc, list vLstTst );

Returns an integer index of the last instance of vLstTst in vLstSrc

  • vLstSrc: source list to check
  • vLstTst: list to look for

if vLstTst is not found in vLstSrc -1 is returned.
the index of the first element in vLstSrc is 0

Code:

  • LSO: 168 Bytes
  • MONO: 512 Bytes
integer uListFindListReverse( list vLstSrc, list vLstTst ){
    integer vIntRtn;
    if (vLstTst != []){
        integer vIntPst = (vLstSrc != []);
        while ((vIntRtn -= ~llListFindList( llList2List( vLstSrc, vIntRtn, vIntPst), vLstTst )) ^ vIntRtn );
    }
    return ~-vIntRtn;
}
/*//--                       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 ]  //*/
/*//--                                                                 --//*/

Notes

  • function loops n+1 times (where n = number of instances of vLstTst in vLstSrc).
    • this may make it slow for large lists containing many copies of vLstTst
  • Unlike llListFindList, this function properly returns -1 if either vLstSrc or vLstTst is an empty list([]).