# [xquery-talk] Deep-equal between sequences

Andrew Welch andrew.j.welch at gmail.com
Wed Jul 11 10:33:36 PDT 2007

```On 7/11/07, Ronald Bourret <rpbourret at rpbourret.com> wrote:
> Hello,
>
> I have two sequences that I would like to compare. The sequences are
> composed of elements and the comparison is true if any member of the
> first sequence is deep-equal to any member of the second sequence.
> (Essentially, I want to do an = operation, but using deep-equal rather
> than atomic equality.)
>
> Can anybody think of a way to do this comparison with the = operator?
> This would give the query engine the chance to optimize the comparison,
> or at least to end the comparison early if a match was found. The
> problem is somewhat simplified by the fact that the definition of the
> elements is <!ELEMENT A (A1, A2)>.
>
> Note that the following is not sufficient:
>
>     let \$firstSeq := ...
>     let \$secondSeq := ...
>     return
>        if ((\$firstSeq/A1 = \$secondSeq/A1) and
>            (\$firstSeq/A2 = \$secondSeq/A2)
>        then fn:true()
>        else fn:false()
>
> The problem with this is that it returns true if any pairs of A1 and A2
> match, while I require that an A1 and A2 with the same parent in the
> first sequence match an A1 and A2 with the same parent in the second
> sequence.
>
> Barring use of the = operator, is there a simple solution to this
> problem that would allow the engine to stop processing on the first
> match, rather than performing n x m deep-equal comparisons and searching
> the resulting sequence for an instance of true?

Do you just need:

return \$firstSeq[for \$x in \$secondSeq return deep-equal(., \$x)]

...add a  to get the first.

cheers
andrew

--
http://andrewjwelch.com
```