source: trunk/SRC/ToBeReviewed/MATRICE/different.pro @ 114

Last change on this file since 114 was 114, checked in by smasson, 18 years ago

new compilation options (compile_opt idl2, strictarrsubs) in each routine

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.7 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5; NAME:different
6;
7; PURPOSE:calcule les elements differents de 2 matrices D'ENTIERS POSITIFS
8;
9; CATEGORY:calcule sur les matrices
10;
11; CALLING SEQUENCE:res=different(a,b)
12;
13; INPUTS:a et b:arrays of positive integers, which need
14;               not be sorted. Duplicate elements are ignored, as they have no
15;               effect on the result
16;
17; KEYWORD PARAMETERS:
18;
19; OUTPUTS:tableau
20;
21; COMMON BLOCKS:
22;
23; SIDE EFFECTS:
24;
25; The empty set is denoted by an array with the first element equal to
26; -1.
27;
28; RESTRICTIONS:
29;
30; These functions will not be efficient on sparse sets with wide
31; ranges, as they trade memory for efficiency. The HISTOGRAM function
32; is used, which creates arrays of size equal to the range of the
33; resulting set.
34;
35; EXAMPLE:
36;
37;   a = [2,4,6,8]
38;   b = [6,1,3,2]
39;   different(a,b) = [ 4, 8]         ; Elements in A but not in B
40;
41; MODIFICATION HISTORY:
42;
43; http://www.dfanning.com/tips/set_operations.html
44;-
45;------------------------------------------------------------
46;------------------------------------------------------------
47;------------------------------------------------------------
48FUNCTION different, a, b 
49;
50  compile_opt idl2, strictarrsubs
51;
52
53   ; = a and (not b) = elements in A but not in B
54
55mina = Min(a, Max=maxa)
56minb = Min(b, Max=maxb)
57IF (minb GT maxa) OR (maxb LT mina) THEN RETURN, a ;No intersection...
58r = Where(Histogram(a, Min=mina, Max=maxa) $
59          *(1-Histogram(b, Min=mina, Max=maxa)), count)
60IF count eq 0 THEN RETURN, -1 ELSE RETURN, r + mina
61END
Note: See TracBrowser for help on using the repository browser.