# 集合

```\$ x=set([5,5,3,4]);
\$ x;
set(4,3,5)

\$ y=set(8 9 9 4 6);
\$ y;
set(6,4,9,8)
```

```\$ x & y;
set(4)
```

```\$ x | y;
set(8,9,6,5,3,4)
```

```\$ x-y;
set(3,5)

\$ y-x;
set(6,9,8)
```

```\$ y^x;
set(5,3,6,9,8)
\$ x^y;
set(8,5,3,6,9)
```

```\$ x=set([4, 6]);
\$ x;
set(6,4)
\$ y=set(8 9 9 4 6);
\$ y;
set(6,4,9,8)

\$ x<=y;
1
// x是y的子集

\$ y>=x;
1
```

```\$ z=set(8 9 4 6);
\$ y==z;
1
// y和z所含的元素完全相同

\$ y in z;
[1,1,1,1]

\$ x in z;
[1,1]

\$ x!=z;
1

\$ z>=x;
1
```

```\$ y=set(8 9 9 4 6);
\$ y;
set(6,4,9,8)

\$ y.append!(3);
set(3,6,4,9,8)
```

```\$ y.erase!(3);
set(6,4,9,8)
```

```\$ y.clear!();
set()
```

```\$ x=1..20000000;
\$ shuffle!(x);
[3123455,13242159,6705807,6107095,10703880,14924328,4435139,19888822,11885962,8535552,17956796,7349822,14777562,13918572,8570589,10706038,6508545,12362405,12742059,16485330,14219242,16979158,6060092,18157360,16132016,12510810,14509873,4402923,6277378,11762392...]

\$ timer y=set(x);
Time elapsed: 8101.53 ms
\$ y;
set(14261183,6712062,10066096,14147249,10177467,6928135,15470317,1348143,19503158,9781988,12709425,3357820,7105084,8740796,10555072,15523011,17319678,19672048,5332111,17767151,4598557,10395083,9715094,8630928,12345383,12834953,11278593,2637131,11464014,14018258...)

\$ timer(1000){19884856 in x};
Time elapsed: 1191.52 ms

\$ timer(1000){19884856 in y};
Time elapsed: 0 ms
```