[DGD] & operato

Petter Nyström jimorie at gmail.com
Tue Nov 6 09:39:38 CET 2007


> In the code that you quoted, the resulting array will contain at most one copy
> of str and nothing else.

This is only true under the assumption that query_users() returns an
array where no two elements are equal, i.e. is a set. A fair
assumption to make, granted, but I thought it was worth pointing out
that the & operator does not guarantee that the the result is a set by
itself.

Similar set operators in LPC are | (union) and ^ (inverted intersection).

Regards,

Jimorie

On Nov 6, 2007 8:50 AM, Mikael Lind <mikkelin at gmail.com> wrote:
> On 06/11/2007, chris . <psych_mayo at hotmail.com> wrote:
> >
> >
> > I saw an unfamiliar operator in the kernel lib...it went something like
> > this:
> > if(sizeof(query_users() & ({str}) ) == 0)
> > I figure this translates something to effect of 'return to me the number
> > of instances str appears in array returned by query_users()'
> > Am i getting it?
> >
>
> Yes. The & operator means bitwise-and for int arguments and set-intersection
> for arrays. The count of any element in the resulting array will be the
> minimum of its counts in the two array arguments. In the code that you
> quoted, the resulting array will contain at most one copy of str and nothing
> else.
>
> Mikael
>
> ___________________________________________
> https://mail.dworkin.nl/mailman/listinfo/dgd
>



More information about the DGD mailing list