;+ ; ; @file_comments ; find the different elements of 2 matrixes of positive whole numbers. ; ; see also union and inter. ; ; @categories ; Calculation ; ; @param a {in}{required} ; arrays of positive integers, which need ; not be sorted. Duplicate elements are ignored, as they have no ; effect on the result ; ; @param b {in}{required} ; see a ; ; @returns ; an array containing the set of values in only a. ; ; The empty set is denoted by an array with the first element equal to ; -1. ; ; @restrictions ; These functions will not be efficient on sparse sets with wide ; ranges, as they trade memory for efficiency. The HISTOGRAM function ; is used, which creates arrays of size equal to the range of the ; resulting set. ; ; @examples ; ; IDL> a = [2,4,6,8] ; IDL> b = [6,1,3,2] ; ; IDL> res=different(a,b) ; 4 8 ; Right because 4 and 8 are in a but not in b ! ; ; IDL> res=different(b,a) ; IDL> print,res ; 1 3 ; ; Right because 1 and 3 are in b but not in a ! ; ; @history ; ; ; @version ; $Id$ ; ;- FUNCTION different, a, b ; compile_opt idl2, strictarrsubs ; ; = a and (not b) = elements in A but not in B mina = Min(a, Max=maxa) minb = Min(b, Max=maxb) IF (minb GT maxa) OR (maxb LT mina) THEN RETURN, a ;No intersection... r = Where(Histogram(a, Min=mina, Max=maxa) $ *(1-Histogram(b, Min=mina, Max=maxa)), count) IF count eq 0 THEN RETURN, -1 ELSE RETURN, r + mina END