1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15function logMapElements(value, key, set) {
16  print(`m[${key}] = ${value}`);
17}
18
19new Set(['foo', 'bar', undefined]).forEach(logMapElements);
20
21
22function logMapElements1(value, key, set) {
23  print(`m[${key}] = ${value}`);
24  set.delete(key);
25  print(set.size);
26}
27
28new Set(['foo', 'bar', undefined]).forEach(logMapElements1);
29
30let mySet = new Set();
31for (let i = 0; i < 1000; i++) {
32    mySet.add(i);
33    mySet.add("key" + i);
34    mySet.add(Symbol("foo"));
35}
36
37const hugeString = BigInt("9007199254740991");
38for (let i = 0; i < 100; i++) {
39    mySet.add(hugeString + BigInt(i));
40}
41
42var intSum = 0;
43var symbolCnt = 0;
44var bigIntSum = BigInt("");
45var stringCnt = 0;
46mySet.forEach((value, key, set) => {
47    if (typeof key == "bigint") {
48        bigIntSum += value;
49        return;
50    }
51    if (typeof key == "number") {
52        intSum += value;
53        return;
54    }
55    if (typeof key == "symbol") {
56        symbolCnt += 1;
57        return;
58    }
59    if (typeof key == "string") {
60        stringCnt += 1;
61        return;
62    }
63});
64
65
66print(intSum);
67print(bigIntSum);
68print(symbolCnt);
69print(stringCnt);
70
71