-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
DictBase.ts
76 lines (55 loc) · 1.56 KB
/
DictBase.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { AddResult, Cursor, Dict, Index, Range } from "./interfaces"
export abstract class DictBase<K, V> implements Dict<K, V> {
constructor(protected index: Index<[K, V], K>) {
}
public equalKeys(key: K): Range<[K, V]> {
return this.index.equalKeys(key);
}
public getValue(key: K): V | undefined {
const cursor = this.index.findKey(key);
if (cursor === null) {
return;
}
return cursor.value[1];
}
public emplace(key: K, value: V): [boolean, Cursor<[K, V]>] {
return this.index.add([key, value]);
}
public hasKey(key: K): boolean {
return this.index.hasKey(key);
}
public findKey(key: K): Cursor<[K, V]> | null {
return this.index.findKey(key);
}
public deleteKey(key: K): number {
return this.index.deleteKey(key);
}
public add(element: [K, V], hint?: any): AddResult<[K, V]> {
return this.index.add(element, hint);
}
public has(element: [K, V]): boolean {
return this.index.has(element);
}
public [Symbol.iterator](): IterableIterator<[K, V]> {
return this.index[Symbol.iterator]();
}
public get size(): number {
return this.index.size;
}
public clear(): void {
this.index.clear();
}
public abstract clone(): Dict<K, V>;
public deleteAt(position: Cursor<[K, V]>): void {
this.index.deleteAt(position);
}
public delete(element: [K, V]): boolean {
return this.index.delete(element);
}
public deleteAll(element: [K, V]): number {
return this.index.deleteAll(element);
}
public toRange(): Range<[K, V]> {
return this.index.toRange();
}
}