1 | ;------------------------------------------------------------ |
---|
2 | ;------------------------------------------------------------ |
---|
3 | ;------------------------------------------------------------ |
---|
4 | ;+ |
---|
5 | ; NAME:union |
---|
6 | ; |
---|
7 | ; PURPOSE:calcule l''union de 2 matrices D'ENTIERS POSITIFS |
---|
8 | ; |
---|
9 | ; CATEGORY:calcule sur les matrices |
---|
10 | ; |
---|
11 | ; CALLING SEQUENCE:res=union(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 | ; union(a,b) = [ 1, 2, 3, 4, 6, 8] ; Elements in either set |
---|
40 | ; |
---|
41 | ; MODIFICATION HISTORY: |
---|
42 | ; |
---|
43 | ; http://www.dfanning.com/tips/set_operations.html |
---|
44 | ;- |
---|
45 | ;------------------------------------------------------------ |
---|
46 | ;------------------------------------------------------------ |
---|
47 | ;------------------------------------------------------------ |
---|
48 | FUNCTION union, a, b |
---|
49 | IF a[0] LT 0 THEN RETURN, b ;A union NULL = a |
---|
50 | IF b[0] LT 0 THEN RETURN, a ;B union NULL = b |
---|
51 | RETURN, Where(Histogram([a,b], OMin = omin)) + omin ; Return combined set |
---|
52 | END |
---|