valueDiff for arrays?
Brian Milby
brian at milby7.com
Fri Aug 3 20:16:47 EDT 2018
I was kind of thinking along those lines too - if the values were wanted.
Looking at "MCArraysDoUnion" in exec-array.cpp, it would be pretty simple
to add code that would do a modified union. The only thing removed would
be matching keys with matching values. That is only if you want to keep
the pLeft values though. If you need to preserve both values or indicate
which keys had differing values, then it is more complicated. The code to
add the syntax and other stuff isn't something I know off hand, but
wouldn't be too difficult.
Of course, then we have to figure out what to name the beast too...
On Fri, Aug 3, 2018 at 6:54 PM, Mark Wieder via use-livecode <
use-livecode at lists.runrev.com> wrote:
> On 08/03/2018 04:26 PM, Brian Milby via use-livecode wrote:
>
>> "symmetric difference" will get you the first part (unique keys)
>>
>
> Nice. One-stop shopping.
>
>
>> You could shorten the compare loop by using "intersect" (to get common
>> keys)
>>
>>
>> function getKeys pLeft, pRight
>> local tIntersect, tResult
>>
>> intersect pLeft with pRight into tIntersect
>> repeat for each key tKey in tIntersect
>> if pLeft[tKey] is not pRight[tKey] then
>> delete variable pRight[tKey]
>> end if
>> end repeat
>>
>> symmetric difference pLeft with pRight into tResult
>> return the keys of tResult
>> end getKeys
>>
>
> I think Richard was aiming for (if I can put words in his mouth here) the
> set of just the elements with duplicate keys but different values. Here's
> my take on that, returning an array with two subarrays:
>
> function getKeys pLeft, pRight
> local tIntersect, tResult
>
> intersect pLeft with pRight into tIntersect
> repeat for each key tKey in tIntersect
> if pLeft[tKey] is pRight[tKey] then
> delete variable pRight[tKey]
> end if
> end repeat
> put tIntersect into tResult["left"]
> intersect pRight with tIntersect into tResult["right"]
> return tResult
> end getKeys
>
>
>
> --
> Mark Wieder
> ahsoftware at gmail.com
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
More information about the use-livecode
mailing list