idlize

Форк
0
53 строки · 1.8 Кб
1
/*
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
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

16
import { float64, int32 } from "./types"
17

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)
22
}
23

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)
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.
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
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.
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++) {
50
        result[i] = data[i]
51
    }
52
    return result
53
}
54

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.