1 | import { flatten, generalize, identify } from '../../utils/array.js';
|
2 | import { factory } from '../../utils/factory.js';
|
3 | var name = 'setDifference';
|
4 | var dependencies = ['typed', 'size', 'subset', 'compareNatural', 'Index', 'DenseMatrix'];
|
5 | export var createSetDifference = factory(name, dependencies, (_ref) => {
|
6 | var {
|
7 | typed,
|
8 | size,
|
9 | subset,
|
10 | compareNatural,
|
11 | Index,
|
12 | DenseMatrix
|
13 | } = _ref;
|
14 |
|
15 | |
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | return typed(name, {
|
37 | 'Array | Matrix, Array | Matrix': function ArrayMatrixArrayMatrix(a1, a2) {
|
38 | var result;
|
39 |
|
40 | if (subset(size(a1), new Index(0)) === 0) {
|
41 |
|
42 | result = [];
|
43 | } else if (subset(size(a2), new Index(0)) === 0) {
|
44 |
|
45 | return flatten(a1.toArray());
|
46 | } else {
|
47 | var b1 = identify(flatten(Array.isArray(a1) ? a1 : a1.toArray()).sort(compareNatural));
|
48 | var b2 = identify(flatten(Array.isArray(a2) ? a2 : a2.toArray()).sort(compareNatural));
|
49 | result = [];
|
50 | var inb2;
|
51 |
|
52 | for (var i = 0; i < b1.length; i++) {
|
53 | inb2 = false;
|
54 |
|
55 | for (var j = 0; j < b2.length; j++) {
|
56 | if (compareNatural(b1[i].value, b2[j].value) === 0 && b1[i].identifier === b2[j].identifier) {
|
57 |
|
58 | inb2 = true;
|
59 | break;
|
60 | }
|
61 | }
|
62 |
|
63 | if (!inb2) {
|
64 | result.push(b1[i]);
|
65 | }
|
66 | }
|
67 | }
|
68 |
|
69 |
|
70 | if (Array.isArray(a1) && Array.isArray(a2)) {
|
71 | return generalize(result);
|
72 | }
|
73 |
|
74 |
|
75 | return new DenseMatrix(generalize(result));
|
76 | }
|
77 | });
|
78 | }); |
\ | No newline at end of file |