@btc-vision/transaction 1.7.3 → 1.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/index.js +1 -1
- package/browser/src/deterministic/AddressMap.d.ts +1 -2
- package/browser/src/deterministic/CustomMap.d.ts +29 -0
- package/browser/src/deterministic/DeterministicSet.d.ts +4 -2
- package/browser/src/deterministic/Map.d.ts +4 -4
- package/browser/src/opnet.d.ts +1 -0
- package/build/deterministic/AddressMap.d.ts +1 -2
- package/build/deterministic/AddressMap.js +16 -29
- package/build/deterministic/CustomMap.d.ts +29 -0
- package/build/deterministic/CustomMap.js +253 -0
- package/build/deterministic/DeterministicMap.js +26 -4
- package/build/deterministic/DeterministicSet.d.ts +4 -2
- package/build/deterministic/DeterministicSet.js +38 -20
- package/build/deterministic/Map.d.ts +4 -4
- package/build/deterministic/Map.js +30 -22
- package/build/opnet.d.ts +1 -0
- package/build/opnet.js +1 -0
- package/package.json +1 -1
- package/src/deterministic/AddressMap.ts +20 -31
- package/src/deterministic/CustomMap.ts +316 -0
- package/src/deterministic/DeterministicMap.ts +30 -4
- package/src/deterministic/DeterministicSet.ts +43 -20
- package/src/deterministic/Map.ts +37 -28
- package/src/opnet.ts +1 -0
package/src/deterministic/Map.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { i32 } from '../utils/types.js';
|
|
2
|
-
|
|
3
1
|
export class Map<K, V> {
|
|
4
2
|
protected _keys: K[] = [];
|
|
5
|
-
protected _values: V
|
|
3
|
+
protected _values: Record<string, V> = {};
|
|
6
4
|
|
|
7
|
-
public get size():
|
|
5
|
+
public get size(): number {
|
|
8
6
|
return this._keys.length;
|
|
9
7
|
}
|
|
10
8
|
|
|
@@ -13,66 +11,77 @@ export class Map<K, V> {
|
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
public *values(): IterableIterator<V> {
|
|
16
|
-
|
|
14
|
+
for (const key of this._keys) {
|
|
15
|
+
yield this._values[this.keyToString(key)];
|
|
16
|
+
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
public *entries(): IterableIterator<[K, V]> {
|
|
20
|
-
for (
|
|
21
|
-
yield [
|
|
20
|
+
for (const key of this._keys) {
|
|
21
|
+
yield [key, this._values[this.keyToString(key)]];
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
public set(key: K, value: V): void {
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
26
|
+
const keyStr = this.keyToString(key);
|
|
27
|
+
if (!this.has(key)) {
|
|
28
28
|
this._keys.push(key);
|
|
29
|
-
this._values.push(value);
|
|
30
|
-
} else {
|
|
31
|
-
this._values[index] = value;
|
|
32
29
|
}
|
|
30
|
+
|
|
31
|
+
this._values[keyStr] = value;
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
public indexOf(key: K):
|
|
36
|
-
for (let i
|
|
37
|
-
if (this._keys[i]
|
|
34
|
+
public indexOf(key: K): number {
|
|
35
|
+
for (let i = 0; i < this._keys.length; i++) {
|
|
36
|
+
if (this._keys[i] === key) {
|
|
38
37
|
return i;
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
|
-
|
|
42
40
|
return -1;
|
|
43
41
|
}
|
|
44
42
|
|
|
45
43
|
public get(key: K): V | undefined {
|
|
46
|
-
|
|
47
|
-
if (index == -1) {
|
|
48
|
-
return undefined;
|
|
49
|
-
}
|
|
50
|
-
return this._values[index];
|
|
44
|
+
return this._values[this.keyToString(key)];
|
|
51
45
|
}
|
|
52
46
|
|
|
53
47
|
public has(key: K): boolean {
|
|
54
|
-
return this.
|
|
48
|
+
return Object.prototype.hasOwnProperty.call(this._values, this.keyToString(key));
|
|
55
49
|
}
|
|
56
50
|
|
|
57
51
|
public delete(key: K): boolean {
|
|
58
|
-
const index
|
|
59
|
-
if (index
|
|
52
|
+
const index = this.indexOf(key);
|
|
53
|
+
if (index === -1) {
|
|
60
54
|
return false;
|
|
61
55
|
}
|
|
62
56
|
|
|
57
|
+
const keyStr = this.keyToString(key);
|
|
63
58
|
this._keys.splice(index, 1);
|
|
64
|
-
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
60
|
+
delete this._values[keyStr];
|
|
65
61
|
return true;
|
|
66
62
|
}
|
|
67
63
|
|
|
68
64
|
public clear(): void {
|
|
69
65
|
this._keys = [];
|
|
70
|
-
this._values =
|
|
66
|
+
this._values = {};
|
|
71
67
|
}
|
|
72
68
|
|
|
73
69
|
*[Symbol.iterator](): IterableIterator<[K, V]> {
|
|
74
|
-
for (
|
|
75
|
-
yield [
|
|
70
|
+
for (const key of this._keys) {
|
|
71
|
+
yield [key, this._values[this.keyToString(key)]];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private keyToString(key: K): string {
|
|
76
|
+
if (typeof key === 'string') {
|
|
77
|
+
return key;
|
|
78
|
+
}
|
|
79
|
+
if (typeof key === 'number' || typeof key === 'boolean') {
|
|
80
|
+
return String(key);
|
|
81
|
+
}
|
|
82
|
+
if (typeof key === 'object' && key !== null) {
|
|
83
|
+
return JSON.stringify(key);
|
|
76
84
|
}
|
|
85
|
+
return String(key);
|
|
77
86
|
}
|
|
78
87
|
}
|
package/src/opnet.ts
CHANGED