refactor
This commit is contained in:
@@ -43,8 +43,8 @@ class NativeEqualityMap<K, V> implements EqualityMap<K, V> {
|
||||
}
|
||||
|
||||
class CustomEqualityMap<K, V> implements EqualityMap<K, V> {
|
||||
readonly #list: [K, V][] = [];
|
||||
readonly #keyComparer: Equater<K>;
|
||||
readonly #list = new Array<[K, V]>();
|
||||
|
||||
constructor(keyComparer: Equater<K>) {
|
||||
this.#keyComparer = keyComparer;
|
||||
@@ -85,9 +85,7 @@ class CustomEqualityMap<K, V> implements EqualityMap<K, V> {
|
||||
}
|
||||
|
||||
remove(key: K) {
|
||||
const length = this.#list.length;
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
for (let i = 0; i < this.#list.length; i++) {
|
||||
if (this.#keyComparer(key, this.#list[i][0])) {
|
||||
const removed = this.#list.splice(i, 1);
|
||||
return removed[0][1];
|
||||
@@ -151,8 +149,8 @@ class NativeAsyncEqualityMap<K, V> implements AsyncEqualityMap<K, V> {
|
||||
}
|
||||
|
||||
class CustomAsyncEqualityMap<K, V> implements AsyncEqualityMap<K, V> {
|
||||
readonly #list: [K, V][] = [];
|
||||
readonly #keyComparer: MaybeAsyncEquater<K>;
|
||||
readonly #list = new Array<[K, V]>();
|
||||
|
||||
constructor(keyComparer: MaybeAsyncEquater<K>) {
|
||||
this.#keyComparer = keyComparer;
|
||||
@@ -193,9 +191,7 @@ class CustomAsyncEqualityMap<K, V> implements AsyncEqualityMap<K, V> {
|
||||
}
|
||||
|
||||
async remove(key: K) {
|
||||
const length = this.#list.length;
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
for (let i = 0; i < this.#list.length; i++) {
|
||||
if (await this.#keyComparer(key, this.#list[i][0])) {
|
||||
const removed = this.#list.splice(i, 1);
|
||||
return removed[0][1];
|
||||
|
||||
Reference in New Issue
Block a user