ImageKnife3.x分支合并master

This commit is contained in:
zgf 2024-07-29 17:20:56 +08:00
parent 4fcbc2b497
commit e048685386
2 changed files with 0 additions and 123 deletions

View File

@ -1,97 +0,0 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:// www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { collections } from '@kit.ArkTS'
import { AsyncLock } from '../imageknife/utils/base/AsyncLock';
import { DiskCacheEntry } from './DiskCacheEntry';
@Sendable
export class CustomSendableMap {
map: collections.Map<string, DiskCacheEntry> = new collections.Map<string, DiskCacheEntry>()
// 获取键对应的值
get(key: string): DiskCacheEntry | undefined{
if (key == null) {
throw new Error('key is null,checking the parameter');
}
return this.map.get(key)
}
/**
* 是否含有key的缓存
*/
hasKey(key: string):boolean {
if (key == null) {
throw new Error('key is null,checking the parameter');
}
return this.map.has(key)
}
// 添加键值对
async put(key: string, value: DiskCacheEntry): Promise<DiskCacheEntry | undefined>{
if (key == null || value == null) {
throw new Error('key or value is invalid,checking the parameter');
}
const lock = new AsyncLock();
await lock.acquire()
try {
let pre = this.map.get(key) as DiskCacheEntry | undefined;
if (this.hasKey(key)) {
this.map.delete(key)
}
this.map.set(key, value);
return pre;
} catch (e) {
throw new Error('put value error');
} finally {
lock.release();
}
}
// 去除键值,(去除键数据中的键名及对应的值)
remove(key: string): boolean {
if (key == null) {
throw new Error('key is null,checking the parameter');
}
return this.map.delete(key)
}
/**
* 获取最先存储的数据的key
*/
getFirstKey(): string{ // keys()可以遍历后需要优化put()方法暂时仅获取index=0的key
return this.map.keys().next().value
}
// 判断键值元素是否为空
isEmpty(): boolean{
return this.map.size == 0;
}
// 获取键值元素大小
size(): number{
return this.map.size;
}
// 遍历Map,执行处理函数. 回调函数 function(key,value,index){..}
each(fn: (value: DiskCacheEntry, key: string, map: collections.Map<string, DiskCacheEntry>) => void) {
this.map.forEach(fn)
}
// 清除键值对
clear() {
this.map.clear()
}
// 遍历key
keys(): IterableIterator<string>{
return this.map.keys()
}
}

View File

@ -1,26 +0,0 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export class PixelEntry {
a: number = 0;
b: number = 0;
r: number = 0;
g: number = 0;
f: number = 0;
pixel: number = 0;
public toString(): string {
return "PixelEntry a:" + this.a + ";b:" + this.b + ";r:" + this.r + ";g:" + this.g + ";f:" + this.f;
}
}