Difference between revisions of "ListCompare"

From Second Life Wiki
Jump to navigation Jump to search
(New page: {{LSL_Function |func=ListCompare |func_desc=Efficiently compares two lists for equality (same contents). |return_type=integer |return_text=TRUE if the lists are equal, FALSE if not. |p1_ty...)
 
(I'm pretty sure you need the zero condition test but i'm leaving it until i can test the behavior.)
Line 18: Line 18:
     integer aL = a != [];
     integer aL = a != [];
     if (aL != (b != [])) return 0;
     if (aL != (b != [])) return 0;
     else if (aL == 0)   return 1;
     if (aL == 0)         return 1;
      
      
     return llListFindList((a = []) + a, (b = []) + b) == 0;
     return !llListFindList((a = []) + a, (b = []) + b);
}</lsl>
}</lsl>

Revision as of 03:31, 4 September 2008

Summary

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

Efficiently compares two lists for equality (same contents).
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

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

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

}</lsl>