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

Home » Public Forums » archive » Re: fast array comparison
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: fast array comparison [message #33149 is a reply to message #33148] Mon, 09 December 2002 08:00 Go to previous messageGo to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
JD Smith (jdsmith@as.arizona.edu) writes:

> This topic was discussed ad naseum over the past couple of years, with
> the critical differences between looking for the values and looking for
> the indices of intersection pointed out. Several different methods were
> compared using HISTOGRAM, SORT, and direct array inflation. Depending on
> your problem size, one of these will be fastest. Usually. ;).
>
> Give it a search on Gusenet.

JD hasn't had his coffee yet this morning. :-)

Search the IDL newsgroup archives on Goggle for "Matching Lists"
by Mark Fardal for the ad nauseam discussion JD mentions. You
may learn more about list searching than you ever wanted to know. :-)

Or, if you just want an answer (no sense reading this
newsgroup if you fall into this category), here you go:

;*********************************************************** ******
FUNCTION SetIntersection, a, b, Indices=indices, Count=count
minab = Min(a, Max=maxa) > Min(b, Max=maxb) ; Intersection of ranges
maxab = maxa < maxb

; If either set is empty, or ranges don't intersect: result = NULL.

IF maxab LT minab OR maxab LT 0 THEN RETURN, -1
hist_a = Histogram(a, Min=minab, Max=maxab, Reverse_Indices=rev_a)
hist_b = Histogram(b, Min=minab, Max=maxab)
r = Where((hist_a NE 0) AND (hist_b NE 0), count)
IF count EQ 0 THEN BEGIN
RETURN, -1
ENDIF ELSE BEGIN
IF Arg_Present(indices) THEN indices = rev_a[rev_a[r]]
RETURN, r + minab
ENDELSE
END
;*********************************************************** ******

IDL> request_array = [5,6,7,8,9,10]
IDL> avail_array = [3,7,8,9,12,13,16]
IDL> int = setintersection(avail_array, request_array, Indices=I)
IDL> print, int, I
7 8 9
1 2 3

Remember, this is one of three possible algorithms discussed in
that series of articles. Choose wisely.

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: calling C from IDL under OS X
Next Topic: 3D Scatterplots

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

Current Time: Wed Oct 08 18:41:26 PDT 2025

Total time taken to generate the page: 0.00556 seconds