Difference between revisions of "ListCompare"

From Second Life Wiki
Jump to navigation Jump to search
m
(add Mono version)
Line 1: Line 1:
{{LSL_Function
{{LSL_Function
|func=ListCompare
|func=ListCompare
|func_desc=Efficiently compares two lists for equality (same contents).
|func_desc=Efficiently compares two lists for equality (same contents in the same order).
|return_type=integer
|return_type=integer
|return_text=TRUE if the lists are equal, FALSE if not.
|return_text=TRUE if the lists are equal, FALSE if not.
Line 15: Line 15:
}}
}}


= Implementation =
= Implementation for LSO =
<lsl>integer ListCompare(list a, list b) {
<lsl>integer ListCompare(list a, list b) {
     integer aL = a != [];
     integer aL = a != [];
Line 23: Line 23:
     return !llListFindList((a = []) + a, (b = []) + b);
     return !llListFindList((a = []) + a, (b = []) + b);
}</lsl>
}</lsl>
= Implementation for MONO =
<lsl>
integer ListCompare(list a, list b)
{
    if (a != b)        return FALSE;    // Note: This is comparing list lengths only
    return !llListFindList(a, b);
}
</lsl>

Revision as of 15:32, 21 April 2014

Summary

Function: integer ListCompare( list a, list b );

Efficiently compares two lists for equality (same contents in the same order).
Returns an integer TRUE if the lists are equal, FALSE if not.

• list a The first list to compare.
• list b The second list to compare.

Examples

<lsl>integer r = ListCompare([1, 2.0, "3"], [1, 2.0, "3"]); // Returns TRUE integer s = ListCompare([1, 2.0, 3], [1, 2.0, "3"]); // Returns FALSE

integer t = ListCompare([], [1, 2.0, "3"]); // Returns FALSE</lsl>

Implementation for LSO

<lsl>integer ListCompare(list a, list b) {

   integer aL = a != [];
   if (aL != (b != [])) return 0;
   if ((aL == 0) && (b == [])) return 1;
   
   return !llListFindList((a = []) + a, (b = []) + b);

}</lsl>

Implementation for MONO

<lsl> integer ListCompare(list a, list b) {

   if (a != b)        return FALSE;    // Note: This is comparing list lengths only
   return !llListFindList(a, b);

} </lsl>