[2] | 1 | ;------------------------------------------------------------ |
---|
| 2 | ;------------------------------------------------------------ |
---|
| 3 | ;------------------------------------------------------------ |
---|
| 4 | ;+ |
---|
| 5 | ; |
---|
[133] | 6 | ; @file_comments |
---|
| 7 | ; calculate tne union between 2 matrixes of whole numbers |
---|
[2] | 8 | ; |
---|
[133] | 9 | ; @categories calculation of matrixes |
---|
[2] | 10 | ; |
---|
[133] | 11 | ; @param a {in}{required} arrays of positive integers, which need |
---|
[2] | 12 | ; not be sorted. Duplicate elements are ignored, as they have no |
---|
| 13 | ; effect on the result |
---|
| 14 | ; |
---|
[133] | 15 | ; @param b {in}{required} see a |
---|
[2] | 16 | ; |
---|
[133] | 17 | ; @returns tableau |
---|
[2] | 18 | ; |
---|
[133] | 19 | ; @restrictions The empty set is denoted by an array with the first element equal to |
---|
[2] | 20 | ; -1. |
---|
| 21 | ; |
---|
[133] | 22 | ; @restrictions These functions will not be efficient on sparse sets with wide |
---|
[2] | 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 | ; |
---|
[133] | 27 | ; @examples a = [2,4,6,8] |
---|
| 28 | ; b = [6,1,3,2] |
---|
| 29 | ; union(a,b) = [ 1, 2, 3, 4, 6, 8] ; Elements in either set |
---|
[2] | 30 | ; |
---|
[133] | 31 | ; @history http://www.dfanning.com/tips/set_operations.html |
---|
[2] | 32 | ; |
---|
[133] | 33 | ; @version $Id$ |
---|
[2] | 34 | ; |
---|
| 35 | ;- |
---|
| 36 | ;------------------------------------------------------------ |
---|
| 37 | ;------------------------------------------------------------ |
---|
| 38 | ;------------------------------------------------------------ |
---|
| 39 | FUNCTION union, a, b |
---|
[114] | 40 | ; |
---|
| 41 | compile_opt idl2, strictarrsubs |
---|
| 42 | ; |
---|
[2] | 43 | IF a[0] LT 0 THEN RETURN, b ;A union NULL = a |
---|
| 44 | IF b[0] LT 0 THEN RETURN, a ;B union NULL = b |
---|
| 45 | RETURN, Where(Histogram([a,b], OMin = omin)) + omin ; Return combined set |
---|
| 46 | END |
---|