1
- export function setUnion < T > ( x : Set < T > , y : Set < T > ) : Set < T > {
1
+ export function setUnion < T > ( x : ReadonlySet < T > , y : ReadonlySet < T > ) : Set < T > {
2
2
return new Set ( [ ...x , ...y ] )
3
3
}
4
4
5
- export function setEqual < T > ( x : Set < T > , y : Set < T > ) : boolean {
6
- return x . size === y . size && setUnion ( x , y ) . size === x . size
7
- }
8
-
9
- export function setIntersection < T > ( x : Set < T > , y : Set < T > ) : Set < T > {
5
+ export function setIntersection < T > (
6
+ x : ReadonlySet < T > ,
7
+ y : ReadonlySet < T > ,
8
+ ) : Set < T > {
10
9
const z = new Set < T > ( )
11
10
for ( const e of x ) {
12
11
if ( y . has ( e ) ) {
@@ -17,7 +16,7 @@ export function setIntersection<T>(x: Set<T>, y: Set<T>): Set<T> {
17
16
return z
18
17
}
19
18
20
- export function setDifference < T > ( x : Set < T > , y : Set < T > ) : Set < T > {
19
+ export function setDifference < T > ( x : ReadonlySet < T > , y : ReadonlySet < T > ) : Set < T > {
21
20
const z = new Set < T > ( )
22
21
for ( const e of x ) {
23
22
if ( ! y . has ( e ) ) {
@@ -28,11 +27,17 @@ export function setDifference<T>(x: Set<T>, y: Set<T>): Set<T> {
28
27
return z
29
28
}
30
29
31
- export function setSymmetricDifference < T > ( x : Set < T > , y : Set < T > ) : Set < T > {
30
+ export function setSymmetricDifference < T > (
31
+ x : ReadonlySet < T > ,
32
+ y : ReadonlySet < T > ,
33
+ ) : Set < T > {
32
34
return setDifference ( setUnion ( x , y ) , setIntersection ( x , y ) )
33
35
}
34
36
35
- export function setIsSubsetOf < T > ( x : Set < T > , y : Set < T > ) : boolean {
37
+ export function setIsSubsetOf < T > (
38
+ x : ReadonlySet < T > ,
39
+ y : ReadonlySet < T > ,
40
+ ) : boolean {
36
41
for ( const e of x ) {
37
42
if ( ! y . has ( e ) ) {
38
43
return false
@@ -42,11 +47,21 @@ export function setIsSubsetOf<T>(x: Set<T>, y: Set<T>): boolean {
42
47
return true
43
48
}
44
49
45
- export function setIsSupersetOf < T > ( x : Set < T > , y : Set < T > ) : boolean {
50
+ export function setEqual < T > ( x : ReadonlySet < T > , y : ReadonlySet < T > ) : boolean {
51
+ return setIsSubsetOf ( x , y ) && setIsSubsetOf ( y , x )
52
+ }
53
+
54
+ export function setIsSupersetOf < T > (
55
+ x : ReadonlySet < T > ,
56
+ y : ReadonlySet < T > ,
57
+ ) : boolean {
46
58
return setIsSubsetOf ( y , x )
47
59
}
48
60
49
- export function setIsDisjointFrom < T > ( x : Set < T > , y : Set < T > ) : boolean {
61
+ export function setIsDisjointFrom < T > (
62
+ x : ReadonlySet < T > ,
63
+ y : ReadonlySet < T > ,
64
+ ) : boolean {
50
65
for ( const e of x ) {
51
66
if ( y . has ( e ) ) {
52
67
return false
0 commit comments