2
* Copyright (c) 2022-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
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 { int32 } from "@koalaui/compat"
17
import { createSha1 } from "./sha1";
19
export class UniqueId {
20
private sha = createSha1()
22
public addString(data: string): UniqueId {
23
this.sha.updateString(data)
27
public addI32(data: int32): UniqueId {
28
this.sha.updateInt32(data)
32
public addF32Array(data: Float32Array): UniqueId {
37
public addI32Array(data: Int32Array): UniqueId {
42
public addU32Array(data: Uint32Array): UniqueId {
47
public addU8Array(data: Uint8Array): UniqueId {
52
public addPtr(data: Uint32Array | number): UniqueId {
53
if (data instanceof Uint32Array) {
54
return this.addU32Array(data)
56
return this.addI32(data as int32)
59
public compute(): string {
60
return this.sha.digest("hex") as string