[DGD] Re: finding an index by a value

Erwin Harte harte at is-here.com
Sat Jan 10 17:53:00 CET 2004


On Sat, Jan 10, 2004 at 04:36:12PM +0000, Robert Forshaw wrote:
> I remember there was an efun in other drivers for finding an index number 
> of an array by the value it contains. Is there any similar kfun to do this, 
> or do I have to write my own in lpc (which will be very slow on large 
> arrays) ?

In order: 1. No; 2. Yes. :)

If all you want to do is check -if- an entry is in an array without
caring at what index, then this does the trick in most cases:

    if (sizeof(arr & ({ element })) > 0) {
        ...found...
    }

It will not work reliably for elements that are themselves arrays or
mappings.

Cheers,

Erwin.
-- 
Erwin Harte <harte at is-here.com>
_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list