1/* 2 * Copyright (c) 2022-2025 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 */ 15 16import { float64, int32, int8 } from "./types" 17 18// TODO: this can be a performance disaster 19// just wait for the library to provide the proper functionality. 20export function asArray<T>(value: T[]): Array<T> { 21 return Array.of<T>(...value) 22} 23 24// TODO: this can be a performance disaster 25// just wait for the library to provide the proper functionality. 26export function Array_from_set<T>(set: Set<T>): Array<T> { 27 const array = new Array<T>() // to avoid creation of undefined content 28 const values = set.values() 29 for (let it = values.next(); it.done != true; it = values.next()) { 30 array.push(it.value as T) 31 } 32 return array 33} 34 35// TODO: this can be a performance disaster 36// just wait for the library to provide the proper functionality. 37export 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 41 } 42 return result 43} 44 45// TODO: this can be a performance disaster 46// just wait for the library to provide the proper functionality. 47export 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++) { 50 result[i] = data[i] 51 } 52 return result 53} 54 55export function int8Array(size: int32): int8[] { 56 return new int8[size] 57} 58 59