source: trunk/SRC/Matrix/different.pro @ 134

Last change on this file since 134 was 134, checked in by navarro, 18 years ago

change *.pro file properties (del eof-style, del executable, set keywords Id

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.6 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5;
6; @file_comments
7; calculate the different elements of 2 matrix of positif whole numbers.
8;
9; @categories Calculation of matrixes
10;
11; @param a {in}{required} arrays of positive integers, which need
12;               not be sorted. Duplicate elements are ignored, as they have no
13;               effect on the result
14;
15; @param b {in}{required} see a
16;
17; @returns tableau
18;
19; @restrictions The empty set is denoted by an array with the first element equal to
20; -1.
21;
22; @restrictions These functions will not be efficient on sparse sets with wide
23; ranges, as they trade memory for efficiency. The HISTOGRAM function
24; is used, which creates arrays of size equal to the range of the
25; resulting set.
26;
27; @examples
28;
29;   a = [2,4,6,8]
30;   b = [6,1,3,2]
31;   different(a,b) = [ 4, 8]         ; Elements in A but not in B
32;
33; @history http://www.dfanning.com/tips/set_operations.html
34;
35; @version $Id$
36;
37;-
38;------------------------------------------------------------
39;------------------------------------------------------------
40;------------------------------------------------------------
41FUNCTION different, a, b 
42;
43  compile_opt idl2, strictarrsubs
44;
45
46   ; = a and (not b) = elements in A but not in B
47
48mina = Min(a, Max=maxa)
49minb = Min(b, Max=maxb)
50IF (minb GT maxa) OR (maxb LT mina) THEN RETURN, a ;No intersection...
51r = Where(Histogram(a, Min=mina, Max=maxa) $
52          *(1-Histogram(b, Min=mina, Max=maxa)), count)
53IF count eq 0 THEN RETURN, -1 ELSE RETURN, r + mina
54END
Note: See TracBrowser for help on using the repository browser.