2
* Copyright (c) 2022-2024 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
7
* http://www.apache.org/licenses/LICENSE-2.0
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.
16
import { float64, int32 } from "./types"
18
// TODO: this can be a performance disaster
19
// just wait for the library to provide the proper functionality.
20
export function asArray<T>(value: T[]): Array<T> {
21
return Array.of<T>(...value)
24
// TODO: this can be a performance disaster
25
// just wait for the library to provide the proper functionality.
26
export function Array_from_set<T>(set: Set<T>): Array<T> {
27
const array: Array<T> = new Array<T>(set.size)
28
const values = set.values()
29
for (let it = values.next(); it.done != true; it = values.next()) {
30
array.push(it.value as T)
35
// TODO: this can be a performance disaster
36
// just wait for the library to provide the proper functionality.
37
export function Array_from_int32(data: Int32Array): number[] {
38
const result: number[] = []
39
for (let i: int32 = 0; i < data.length; i++) {
40
result[i] = data.at(i) as number
45
// TODO: this can be a performance disaster
46
// just wait for the library to provide the proper functionality.
47
export function Array_from_number(data: float64[]): Array<float64> {
48
const result = new Array<number>(data.length)
49
for (let i: int32 = 0; i < data.length; i++) {