;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ ;+ ; NAME:different ; ; PURPOSE:calcule les elements differents de 2 matrices D'ENTIERS POSITIFS ; ; CATEGORY:calcule sur les matrices ; ; CALLING SEQUENCE:res=different(a,b) ; ; INPUTS:a et b:arrays of positive integers, which need ; not be sorted. Duplicate elements are ignored, as they have no ; effect on the result ; ; KEYWORD PARAMETERS: ; ; OUTPUTS:tableau ; ; COMMON BLOCKS: ; ; SIDE EFFECTS: ; ; 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. ; ; EXAMPLE: ; ; a = [2,4,6,8] ; b = [6,1,3,2] ; different(a,b) = [ 4, 8] ; Elements in A but not in B ; ; MODIFICATION HISTORY: ; ; http://www.dfanning.com/tips/set_operations.html ;- ;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ FUNCTION different, a, b ; = 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