comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Finding a value in a array efficiently
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Finding a value in a array efficiently [message #48349 is a reply to message #48348] Thu, 13 April 2006 15:39 Go to previous messageGo to previous message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Thu, 13 Apr 2006 13:31:42 -0700, Wayne Landsman wrote:

> I was asked an apparently simple question -- what is the most efficient
> way in IDL to determine if a particular scalar value is in an array.
[..]
> A more efficent (if less transparent) method might be
>
> found = 1 - array_equal( array EQ value, 0)
>
> where (array EQ value) will contain all zeros if there is no match.
> The ARRAY_EQUAL(x,0) function returns a value of zero as soon as it
> finds a non-zero value in x. So we are part way there but (array EQ
> value) still requires testing every value of "array".
>
> So what we need is a new ARRAY_OR(x,y) function which returns 1 as
> soon as it finds any match between X and Y. Or am I missing another
> method? --Wayne

Just negate your ARRAY_EQUAL. I use this all the time:

in_array=~array_equal(array NE value,1b)

In English that's "is it not everywhere not equal to the value". As soon
as it comes across (array NE value)=0 (i.e. a place where it's "not not
equal") it will return.

JD
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Update Shared memory Structure
Next Topic: Free source code diagramming programs

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 14:59:09 PDT 2025

Total time taken to generate the page: 0.00410 seconds