@monstermann/set 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Set/difference.mjs
CHANGED
|
@@ -24,15 +24,11 @@ import { dfdlT } from "@monstermann/dfdl";
|
|
|
24
24
|
*/
|
|
25
25
|
const difference = dfdlT((target, source) => {
|
|
26
26
|
if (source.size === 0) return target;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
return result;
|
|
34
|
-
}
|
|
35
|
-
return target;
|
|
27
|
+
let hasOverlap = false;
|
|
28
|
+
const result = /* @__PURE__ */ new Set();
|
|
29
|
+
for (const value of target) if (source.has(value)) hasOverlap = true;
|
|
30
|
+
else result.add(value);
|
|
31
|
+
return hasOverlap ? result : target;
|
|
36
32
|
}, 2);
|
|
37
33
|
|
|
38
34
|
//#endregion
|
|
@@ -25,15 +25,11 @@ import { dfdlT } from "@monstermann/dfdl";
|
|
|
25
25
|
const intersection = dfdlT((target, source) => {
|
|
26
26
|
if (target.size === 0) return target;
|
|
27
27
|
if (source.size === 0) return source;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
return result;
|
|
35
|
-
}
|
|
36
|
-
return target;
|
|
28
|
+
let hasNonMatch = false;
|
|
29
|
+
const result = /* @__PURE__ */ new Set();
|
|
30
|
+
for (const value of target) if (!source.has(value)) hasNonMatch = true;
|
|
31
|
+
else result.add(value);
|
|
32
|
+
return hasNonMatch ? result : target;
|
|
37
33
|
}, 2);
|
|
38
34
|
|
|
39
35
|
//#endregion
|
|
@@ -25,21 +25,19 @@ import { dfdlT } from "@monstermann/dfdl";
|
|
|
25
25
|
const symmetricDifference = dfdlT((target, source) => {
|
|
26
26
|
if (source.size === 0) return target;
|
|
27
27
|
if (target.size === 0) return source;
|
|
28
|
-
let
|
|
28
|
+
let result;
|
|
29
|
+
let allMatch = true;
|
|
29
30
|
for (const a of target) if (!source.has(a)) {
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
allMatch = false;
|
|
32
|
+
result ??= /* @__PURE__ */ new Set();
|
|
33
|
+
result.add(a);
|
|
32
34
|
}
|
|
33
|
-
if (!
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
35
|
+
for (const b of source) if (!target.has(b)) {
|
|
36
|
+
allMatch = false;
|
|
37
|
+
result ??= /* @__PURE__ */ new Set();
|
|
38
|
+
result.add(b);
|
|
38
39
|
}
|
|
39
|
-
if (
|
|
40
|
-
const result = /* @__PURE__ */ new Set();
|
|
41
|
-
for (const a of target) if (!source.has(a)) result.add(a);
|
|
42
|
-
for (const b of source) if (!target.has(b)) result.add(b);
|
|
40
|
+
if (allMatch) return /* @__PURE__ */ new Set();
|
|
43
41
|
return result;
|
|
44
42
|
}, 2);
|
|
45
43
|
|
package/dist/Set/union.mjs
CHANGED
|
@@ -25,13 +25,15 @@ import { dfdlT } from "@monstermann/dfdl";
|
|
|
25
25
|
const union = dfdlT((target, source) => {
|
|
26
26
|
if (source.size === 0) return target;
|
|
27
27
|
if (target.size === 0) return source;
|
|
28
|
+
let result;
|
|
28
29
|
for (const element of source) if (!target.has(element)) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
if (result === void 0) {
|
|
31
|
+
result = /* @__PURE__ */ new Set();
|
|
32
|
+
for (const a of target) result.add(a);
|
|
33
|
+
}
|
|
34
|
+
result.add(element);
|
|
33
35
|
}
|
|
34
|
-
return target;
|
|
36
|
+
return result ?? target;
|
|
35
37
|
}, 2);
|
|
36
38
|
|
|
37
39
|
//#endregion
|