@btc-vision/transaction 1.7.4 → 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/Map.d.ts +2 -1
- 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/Map.d.ts +2 -1
- 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/Map.ts +35 -24
- package/src/opnet.ts +1 -0
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Address } from '../keypair/Address.js';
|
|
2
2
|
export declare class AddressMap<V> {
|
|
3
3
|
private items;
|
|
4
|
-
private keyOrder;
|
|
5
4
|
constructor(iterable?: ReadonlyArray<readonly [Address, V]> | null);
|
|
6
5
|
get size(): number;
|
|
7
|
-
set(key: Address, value: V):
|
|
6
|
+
set(key: Address, value: V): this;
|
|
8
7
|
get(key: Address): V | undefined;
|
|
9
8
|
has(key: Address): boolean;
|
|
10
9
|
delete(key: Address): boolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare class CustomMap<K, V> {
|
|
2
|
+
#private;
|
|
3
|
+
private static readonly INITIAL_CAPACITY;
|
|
4
|
+
private static readonly LOAD_FACTOR;
|
|
5
|
+
private deleted;
|
|
6
|
+
private capacity;
|
|
7
|
+
constructor();
|
|
8
|
+
private _size;
|
|
9
|
+
get size(): number;
|
|
10
|
+
set(key: K, value: V): boolean;
|
|
11
|
+
get(key: K): V | undefined;
|
|
12
|
+
has(key: K): boolean;
|
|
13
|
+
indexOf(key: K): number;
|
|
14
|
+
delete(key: K): boolean;
|
|
15
|
+
clear(): void;
|
|
16
|
+
entries(): MapIterator<[K, V]>;
|
|
17
|
+
keys(): MapIterator<K>;
|
|
18
|
+
values(): MapIterator<V>;
|
|
19
|
+
[Symbol.iterator](): MapIterator<[K, V]>;
|
|
20
|
+
private hashBigInt;
|
|
21
|
+
private hash;
|
|
22
|
+
private hashBuffer;
|
|
23
|
+
private equals;
|
|
24
|
+
private buffersEqual;
|
|
25
|
+
private getBytes;
|
|
26
|
+
private findIndex;
|
|
27
|
+
private findInsertIndex;
|
|
28
|
+
private resize;
|
|
29
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare class Map<K, V> {
|
|
2
2
|
protected _keys: K[];
|
|
3
|
-
protected _values: V
|
|
3
|
+
protected _values: Record<string, V>;
|
|
4
4
|
get size(): number;
|
|
5
5
|
keys(): IterableIterator<K>;
|
|
6
6
|
values(): IterableIterator<V>;
|
|
@@ -12,4 +12,5 @@ export declare class Map<K, V> {
|
|
|
12
12
|
delete(key: K): boolean;
|
|
13
13
|
clear(): void;
|
|
14
14
|
[Symbol.iterator](): IterableIterator<[K, V]>;
|
|
15
|
+
private keyToString;
|
|
15
16
|
}
|
package/browser/src/opnet.d.ts
CHANGED
|
@@ -76,6 +76,7 @@ export * from './transaction/browser/Web3Provider.js';
|
|
|
76
76
|
export * from './keypair/Secp256k1PointDeriver.js';
|
|
77
77
|
export * from './transaction/ContractAddress.js';
|
|
78
78
|
export * from './deterministic/Map.js';
|
|
79
|
+
export * from './deterministic/CustomMap.js';
|
|
79
80
|
declare global {
|
|
80
81
|
interface Window {
|
|
81
82
|
unisat?: Unisat;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Address } from '../keypair/Address.js';
|
|
2
2
|
export declare class AddressMap<V> {
|
|
3
3
|
private items;
|
|
4
|
-
private keyOrder;
|
|
5
4
|
constructor(iterable?: ReadonlyArray<readonly [Address, V]> | null);
|
|
6
5
|
get size(): number;
|
|
7
|
-
set(key: Address, value: V):
|
|
6
|
+
set(key: Address, value: V): this;
|
|
8
7
|
get(key: Address): V | undefined;
|
|
9
8
|
has(key: Address): boolean;
|
|
10
9
|
delete(key: Address): boolean;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { Address } from '../keypair/Address.js';
|
|
1
2
|
import { Map } from './Map.js';
|
|
2
3
|
export class AddressMap {
|
|
3
4
|
constructor(iterable) {
|
|
4
5
|
this.items = new Map();
|
|
5
|
-
this.keyOrder = [];
|
|
6
6
|
if (iterable) {
|
|
7
7
|
for (const [key, value] of iterable) {
|
|
8
8
|
this.set(key, value);
|
|
@@ -10,14 +10,12 @@ export class AddressMap {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
get size() {
|
|
13
|
-
return this.
|
|
13
|
+
return this.items.size;
|
|
14
14
|
}
|
|
15
15
|
set(key, value) {
|
|
16
16
|
const keyBigInt = key.toBigInt();
|
|
17
|
-
if (!this.items.has(keyBigInt)) {
|
|
18
|
-
this.keyOrder.push(key);
|
|
19
|
-
}
|
|
20
17
|
this.items.set(keyBigInt, value);
|
|
18
|
+
return this;
|
|
21
19
|
}
|
|
22
20
|
get(key) {
|
|
23
21
|
return this.items.get(key.toBigInt());
|
|
@@ -27,47 +25,36 @@ export class AddressMap {
|
|
|
27
25
|
}
|
|
28
26
|
delete(key) {
|
|
29
27
|
const keyBigInt = key.toBigInt();
|
|
30
|
-
|
|
31
|
-
this.keyOrder = this.keyOrder.filter((k) => k.toBigInt() !== keyBigInt);
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
28
|
+
return this.items.delete(keyBigInt);
|
|
35
29
|
}
|
|
36
30
|
clear() {
|
|
37
31
|
this.items.clear();
|
|
38
|
-
this.keyOrder = [];
|
|
39
32
|
}
|
|
40
33
|
indexOf(address) {
|
|
41
|
-
|
|
42
|
-
for (let i = 0; i < this.keyOrder.length; i++) {
|
|
43
|
-
if (this.keyOrder[i].toBigInt() === addressBigInt) {
|
|
44
|
-
return i;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return -1;
|
|
34
|
+
return this.items.indexOf(address.toBigInt());
|
|
48
35
|
}
|
|
49
36
|
*entries() {
|
|
50
|
-
for (const
|
|
51
|
-
yield [
|
|
37
|
+
for (const [keyBigInt, value] of this.items.entries()) {
|
|
38
|
+
yield [Address.fromBigInt(keyBigInt), value];
|
|
52
39
|
}
|
|
53
40
|
}
|
|
54
41
|
*keys() {
|
|
55
|
-
|
|
42
|
+
for (const keyBigInt of this.items.keys()) {
|
|
43
|
+
yield Address.fromBigInt(keyBigInt);
|
|
44
|
+
}
|
|
56
45
|
}
|
|
57
46
|
*values() {
|
|
58
|
-
for (const
|
|
59
|
-
yield
|
|
47
|
+
for (const value of this.items.values()) {
|
|
48
|
+
yield value;
|
|
60
49
|
}
|
|
61
50
|
}
|
|
62
51
|
forEach(callback, thisArg) {
|
|
63
|
-
for (const
|
|
64
|
-
|
|
52
|
+
for (const [keyBigInt, value] of this.items.entries()) {
|
|
53
|
+
const key = Address.fromBigInt(keyBigInt);
|
|
54
|
+
callback.call(thisArg, value, key, this);
|
|
65
55
|
}
|
|
66
56
|
}
|
|
67
57
|
*[Symbol.iterator]() {
|
|
68
|
-
|
|
69
|
-
const key = this.keyOrder[i];
|
|
70
|
-
yield [key, this.items.get(key.toBigInt())];
|
|
71
|
-
}
|
|
58
|
+
yield* this.entries();
|
|
72
59
|
}
|
|
73
60
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare class CustomMap<K, V> {
|
|
2
|
+
#private;
|
|
3
|
+
private static readonly INITIAL_CAPACITY;
|
|
4
|
+
private static readonly LOAD_FACTOR;
|
|
5
|
+
private deleted;
|
|
6
|
+
private capacity;
|
|
7
|
+
constructor();
|
|
8
|
+
private _size;
|
|
9
|
+
get size(): number;
|
|
10
|
+
set(key: K, value: V): boolean;
|
|
11
|
+
get(key: K): V | undefined;
|
|
12
|
+
has(key: K): boolean;
|
|
13
|
+
indexOf(key: K): number;
|
|
14
|
+
delete(key: K): boolean;
|
|
15
|
+
clear(): void;
|
|
16
|
+
entries(): MapIterator<[K, V]>;
|
|
17
|
+
keys(): MapIterator<K>;
|
|
18
|
+
values(): MapIterator<V>;
|
|
19
|
+
[Symbol.iterator](): MapIterator<[K, V]>;
|
|
20
|
+
private hashBigInt;
|
|
21
|
+
private hash;
|
|
22
|
+
private hashBuffer;
|
|
23
|
+
private equals;
|
|
24
|
+
private buffersEqual;
|
|
25
|
+
private getBytes;
|
|
26
|
+
private findIndex;
|
|
27
|
+
private findInsertIndex;
|
|
28
|
+
private resize;
|
|
29
|
+
}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _CustomMap_keys, _CustomMap_values;
|
|
13
|
+
export class CustomMap {
|
|
14
|
+
constructor() {
|
|
15
|
+
_CustomMap_keys.set(this, void 0);
|
|
16
|
+
_CustomMap_values.set(this, void 0);
|
|
17
|
+
this._size = 0;
|
|
18
|
+
this.capacity = CustomMap.INITIAL_CAPACITY;
|
|
19
|
+
__classPrivateFieldSet(this, _CustomMap_keys, new Array(this.capacity), "f");
|
|
20
|
+
__classPrivateFieldSet(this, _CustomMap_values, new Array(this.capacity), "f");
|
|
21
|
+
this.deleted = new Array(this.capacity).fill(false);
|
|
22
|
+
}
|
|
23
|
+
get size() {
|
|
24
|
+
return this._size;
|
|
25
|
+
}
|
|
26
|
+
set(key, value) {
|
|
27
|
+
let exist = true;
|
|
28
|
+
const index = this.findInsertIndex(key);
|
|
29
|
+
if (__classPrivateFieldGet(this, _CustomMap_keys, "f")[index] === undefined || this.deleted[index]) {
|
|
30
|
+
this._size++;
|
|
31
|
+
exist = false;
|
|
32
|
+
}
|
|
33
|
+
__classPrivateFieldGet(this, _CustomMap_keys, "f")[index] = key;
|
|
34
|
+
__classPrivateFieldGet(this, _CustomMap_values, "f")[index] = value;
|
|
35
|
+
this.deleted[index] = false;
|
|
36
|
+
if (this._size > this.capacity * CustomMap.LOAD_FACTOR) {
|
|
37
|
+
this.resize();
|
|
38
|
+
}
|
|
39
|
+
return exist;
|
|
40
|
+
}
|
|
41
|
+
get(key) {
|
|
42
|
+
const index = this.findIndex(key);
|
|
43
|
+
return index === -1 ? undefined : __classPrivateFieldGet(this, _CustomMap_values, "f")[index];
|
|
44
|
+
}
|
|
45
|
+
has(key) {
|
|
46
|
+
return this.findIndex(key) !== -1;
|
|
47
|
+
}
|
|
48
|
+
indexOf(key) {
|
|
49
|
+
return this.findIndex(key);
|
|
50
|
+
}
|
|
51
|
+
delete(key) {
|
|
52
|
+
const index = this.findIndex(key);
|
|
53
|
+
if (index === -1) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
__classPrivateFieldGet(this, _CustomMap_keys, "f")[index] = undefined;
|
|
57
|
+
__classPrivateFieldGet(this, _CustomMap_values, "f")[index] = undefined;
|
|
58
|
+
this.deleted[index] = true;
|
|
59
|
+
this._size--;
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
clear() {
|
|
63
|
+
__classPrivateFieldSet(this, _CustomMap_keys, new Array(this.capacity), "f");
|
|
64
|
+
__classPrivateFieldSet(this, _CustomMap_values, new Array(this.capacity), "f");
|
|
65
|
+
this.deleted = new Array(this.capacity).fill(false);
|
|
66
|
+
this._size = 0;
|
|
67
|
+
}
|
|
68
|
+
*entries() {
|
|
69
|
+
for (let i = 0; i < this.capacity; i++) {
|
|
70
|
+
if (__classPrivateFieldGet(this, _CustomMap_keys, "f")[i] !== undefined && !this.deleted[i]) {
|
|
71
|
+
yield [__classPrivateFieldGet(this, _CustomMap_keys, "f")[i], __classPrivateFieldGet(this, _CustomMap_values, "f")[i]];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
*keys() {
|
|
76
|
+
for (let i = 0; i < this.capacity; i++) {
|
|
77
|
+
if (__classPrivateFieldGet(this, _CustomMap_keys, "f")[i] !== undefined && !this.deleted[i]) {
|
|
78
|
+
yield __classPrivateFieldGet(this, _CustomMap_keys, "f")[i];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
*values() {
|
|
83
|
+
for (let i = 0; i < this.capacity; i++) {
|
|
84
|
+
if (__classPrivateFieldGet(this, _CustomMap_keys, "f")[i] !== undefined && !this.deleted[i]) {
|
|
85
|
+
yield __classPrivateFieldGet(this, _CustomMap_values, "f")[i];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
*[(_CustomMap_keys = new WeakMap(), _CustomMap_values = new WeakMap(), Symbol.iterator)]() {
|
|
90
|
+
yield* this.entries();
|
|
91
|
+
}
|
|
92
|
+
hashBigInt(key) {
|
|
93
|
+
if (key >= -2147483648n && key <= 2147483647n) {
|
|
94
|
+
return Number(key) | 0;
|
|
95
|
+
}
|
|
96
|
+
let hash = 2166136261;
|
|
97
|
+
let n = key < 0n ? -key : key;
|
|
98
|
+
while (n > 0n) {
|
|
99
|
+
const chunk = Number(n & 0xffffffffn);
|
|
100
|
+
hash ^= chunk;
|
|
101
|
+
hash = Math.imul(hash, 16777619);
|
|
102
|
+
n = n >> 32n;
|
|
103
|
+
}
|
|
104
|
+
if (key < 0n) {
|
|
105
|
+
hash ^= 0x80000000;
|
|
106
|
+
hash = Math.imul(hash, 16777619);
|
|
107
|
+
}
|
|
108
|
+
return Math.abs(hash);
|
|
109
|
+
}
|
|
110
|
+
hash(key) {
|
|
111
|
+
let hash = 0;
|
|
112
|
+
switch (typeof key) {
|
|
113
|
+
case 'number':
|
|
114
|
+
if (key !== key)
|
|
115
|
+
return 0x7ff8000000000000;
|
|
116
|
+
if (!isFinite(key))
|
|
117
|
+
return key > 0 ? 0x7ff0000000000000 : 0xfff0000000000000;
|
|
118
|
+
hash = key | 0;
|
|
119
|
+
break;
|
|
120
|
+
case 'string':
|
|
121
|
+
hash = 2166136261;
|
|
122
|
+
for (let i = 0; i < key.length; i++) {
|
|
123
|
+
hash ^= key.charCodeAt(i);
|
|
124
|
+
hash = Math.imul(hash, 16777619);
|
|
125
|
+
}
|
|
126
|
+
break;
|
|
127
|
+
case 'boolean':
|
|
128
|
+
hash = key ? 1231 : 1237;
|
|
129
|
+
break;
|
|
130
|
+
case 'symbol': {
|
|
131
|
+
const desc = key.description || '';
|
|
132
|
+
hash = this.hash(desc);
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
case 'bigint':
|
|
136
|
+
hash = this.hashBigInt(key);
|
|
137
|
+
break;
|
|
138
|
+
case 'undefined':
|
|
139
|
+
hash = 0;
|
|
140
|
+
break;
|
|
141
|
+
case 'object':
|
|
142
|
+
if (key === null) {
|
|
143
|
+
hash = 0;
|
|
144
|
+
}
|
|
145
|
+
else if (key instanceof Date) {
|
|
146
|
+
hash = key.getTime() | 0;
|
|
147
|
+
}
|
|
148
|
+
else if (ArrayBuffer.isView(key) || key instanceof ArrayBuffer) {
|
|
149
|
+
hash = this.hashBuffer(key);
|
|
150
|
+
}
|
|
151
|
+
else if (Array.isArray(key)) {
|
|
152
|
+
hash = 1;
|
|
153
|
+
for (const item of key) {
|
|
154
|
+
hash = Math.imul(hash, 31) + this.hash(item);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
throw new Error('Raw object not supported.');
|
|
159
|
+
}
|
|
160
|
+
break;
|
|
161
|
+
case 'function':
|
|
162
|
+
hash = this.hash(key.toString());
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
return Math.abs(hash) % this.capacity;
|
|
166
|
+
}
|
|
167
|
+
hashBuffer(buffer) {
|
|
168
|
+
let bytes;
|
|
169
|
+
if (buffer instanceof ArrayBuffer) {
|
|
170
|
+
bytes = new Uint8Array(buffer);
|
|
171
|
+
}
|
|
172
|
+
else if (ArrayBuffer.isView(buffer)) {
|
|
173
|
+
bytes = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
return 0;
|
|
177
|
+
}
|
|
178
|
+
let hash = 2166136261;
|
|
179
|
+
for (let i = 0; i < Math.min(bytes.length, 100); i++) {
|
|
180
|
+
hash ^= bytes[i];
|
|
181
|
+
hash = Math.imul(hash, 16777619);
|
|
182
|
+
}
|
|
183
|
+
return hash;
|
|
184
|
+
}
|
|
185
|
+
equals(a, b) {
|
|
186
|
+
if (a === b)
|
|
187
|
+
return true;
|
|
188
|
+
if (typeof a === 'number' && typeof b === 'number' && a !== a && b !== b) {
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
if ((ArrayBuffer.isView(a) || a instanceof ArrayBuffer) &&
|
|
192
|
+
(ArrayBuffer.isView(b) || b instanceof ArrayBuffer)) {
|
|
193
|
+
return this.buffersEqual(a, b);
|
|
194
|
+
}
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
buffersEqual(a, b) {
|
|
198
|
+
const bytesA = this.getBytes(a);
|
|
199
|
+
const bytesB = this.getBytes(b);
|
|
200
|
+
if (bytesA.length !== bytesB.length)
|
|
201
|
+
return false;
|
|
202
|
+
for (let i = 0; i < bytesA.length; i++) {
|
|
203
|
+
if (bytesA[i] !== bytesB[i])
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
getBytes(buffer) {
|
|
209
|
+
if (buffer instanceof ArrayBuffer) {
|
|
210
|
+
return new Uint8Array(buffer);
|
|
211
|
+
}
|
|
212
|
+
else if (ArrayBuffer.isView(buffer)) {
|
|
213
|
+
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
214
|
+
}
|
|
215
|
+
return new Uint8Array(0);
|
|
216
|
+
}
|
|
217
|
+
findIndex(key) {
|
|
218
|
+
let index = this.hash(key);
|
|
219
|
+
while (__classPrivateFieldGet(this, _CustomMap_keys, "f")[index] !== undefined || this.deleted[index]) {
|
|
220
|
+
if (__classPrivateFieldGet(this, _CustomMap_keys, "f")[index] !== undefined && this.equals(__classPrivateFieldGet(this, _CustomMap_keys, "f")[index], key)) {
|
|
221
|
+
return index;
|
|
222
|
+
}
|
|
223
|
+
index = (index + 1) % this.capacity;
|
|
224
|
+
}
|
|
225
|
+
return -1;
|
|
226
|
+
}
|
|
227
|
+
findInsertIndex(key) {
|
|
228
|
+
let index = this.hash(key);
|
|
229
|
+
while (__classPrivateFieldGet(this, _CustomMap_keys, "f")[index] !== undefined && !this.deleted[index]) {
|
|
230
|
+
if (this.equals(__classPrivateFieldGet(this, _CustomMap_keys, "f")[index], key)) {
|
|
231
|
+
return index;
|
|
232
|
+
}
|
|
233
|
+
index = (index + 1) % this.capacity;
|
|
234
|
+
}
|
|
235
|
+
return index;
|
|
236
|
+
}
|
|
237
|
+
resize() {
|
|
238
|
+
const oldKeys = __classPrivateFieldGet(this, _CustomMap_keys, "f");
|
|
239
|
+
const oldValues = __classPrivateFieldGet(this, _CustomMap_values, "f");
|
|
240
|
+
this.capacity *= 2;
|
|
241
|
+
__classPrivateFieldSet(this, _CustomMap_keys, new Array(this.capacity), "f");
|
|
242
|
+
__classPrivateFieldSet(this, _CustomMap_values, new Array(this.capacity), "f");
|
|
243
|
+
this.deleted = new Array(this.capacity).fill(false);
|
|
244
|
+
this._size = 0;
|
|
245
|
+
for (let i = 0; i < oldKeys.length; i++) {
|
|
246
|
+
if (oldKeys[i] !== undefined && !this.deleted[i]) {
|
|
247
|
+
this.set(oldKeys[i], oldValues[i]);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
CustomMap.INITIAL_CAPACITY = 16;
|
|
253
|
+
CustomMap.LOAD_FACTOR = 0.75;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare class Map<K, V> {
|
|
2
2
|
protected _keys: K[];
|
|
3
|
-
protected _values: V
|
|
3
|
+
protected _values: Record<string, V>;
|
|
4
4
|
get size(): number;
|
|
5
5
|
keys(): IterableIterator<K>;
|
|
6
6
|
values(): IterableIterator<V>;
|
|
@@ -12,4 +12,5 @@ export declare class Map<K, V> {
|
|
|
12
12
|
delete(key: K): boolean;
|
|
13
13
|
clear(): void;
|
|
14
14
|
[Symbol.iterator](): IterableIterator<[K, V]>;
|
|
15
|
+
private keyToString;
|
|
15
16
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export class Map {
|
|
2
2
|
constructor() {
|
|
3
3
|
this._keys = [];
|
|
4
|
-
this._values =
|
|
4
|
+
this._values = {};
|
|
5
5
|
}
|
|
6
6
|
get size() {
|
|
7
7
|
return this._keys.length;
|
|
@@ -10,57 +10,65 @@ export class Map {
|
|
|
10
10
|
yield* this._keys;
|
|
11
11
|
}
|
|
12
12
|
*values() {
|
|
13
|
-
|
|
13
|
+
for (const key of this._keys) {
|
|
14
|
+
yield this._values[this.keyToString(key)];
|
|
15
|
+
}
|
|
14
16
|
}
|
|
15
17
|
*entries() {
|
|
16
|
-
for (
|
|
17
|
-
yield [
|
|
18
|
+
for (const key of this._keys) {
|
|
19
|
+
yield [key, this._values[this.keyToString(key)]];
|
|
18
20
|
}
|
|
19
21
|
}
|
|
20
22
|
set(key, value) {
|
|
21
|
-
const
|
|
22
|
-
if (
|
|
23
|
+
const keyStr = this.keyToString(key);
|
|
24
|
+
if (!this.has(key)) {
|
|
23
25
|
this._keys.push(key);
|
|
24
|
-
this._values.push(value);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
this._values[index] = value;
|
|
28
26
|
}
|
|
27
|
+
this._values[keyStr] = value;
|
|
29
28
|
}
|
|
30
29
|
indexOf(key) {
|
|
31
30
|
for (let i = 0; i < this._keys.length; i++) {
|
|
32
|
-
if (this._keys[i]
|
|
31
|
+
if (this._keys[i] === key) {
|
|
33
32
|
return i;
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
35
|
return -1;
|
|
37
36
|
}
|
|
38
37
|
get(key) {
|
|
39
|
-
|
|
40
|
-
if (index == -1) {
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
return this._values[index];
|
|
38
|
+
return this._values[this.keyToString(key)];
|
|
44
39
|
}
|
|
45
40
|
has(key) {
|
|
46
|
-
return this.
|
|
41
|
+
return Object.prototype.hasOwnProperty.call(this._values, this.keyToString(key));
|
|
47
42
|
}
|
|
48
43
|
delete(key) {
|
|
49
44
|
const index = this.indexOf(key);
|
|
50
|
-
if (index
|
|
45
|
+
if (index === -1) {
|
|
51
46
|
return false;
|
|
52
47
|
}
|
|
48
|
+
const keyStr = this.keyToString(key);
|
|
53
49
|
this._keys.splice(index, 1);
|
|
54
|
-
this._values
|
|
50
|
+
delete this._values[keyStr];
|
|
55
51
|
return true;
|
|
56
52
|
}
|
|
57
53
|
clear() {
|
|
58
54
|
this._keys = [];
|
|
59
|
-
this._values =
|
|
55
|
+
this._values = {};
|
|
60
56
|
}
|
|
61
57
|
*[Symbol.iterator]() {
|
|
62
|
-
for (
|
|
63
|
-
yield [
|
|
58
|
+
for (const key of this._keys) {
|
|
59
|
+
yield [key, this._values[this.keyToString(key)]];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
keyToString(key) {
|
|
63
|
+
if (typeof key === 'string') {
|
|
64
|
+
return key;
|
|
65
|
+
}
|
|
66
|
+
if (typeof key === 'number' || typeof key === 'boolean') {
|
|
67
|
+
return String(key);
|
|
68
|
+
}
|
|
69
|
+
if (typeof key === 'object' && key !== null) {
|
|
70
|
+
return JSON.stringify(key);
|
|
64
71
|
}
|
|
72
|
+
return String(key);
|
|
65
73
|
}
|
|
66
74
|
}
|
package/build/opnet.d.ts
CHANGED
|
@@ -76,6 +76,7 @@ export * from './transaction/browser/Web3Provider.js';
|
|
|
76
76
|
export * from './keypair/Secp256k1PointDeriver.js';
|
|
77
77
|
export * from './transaction/ContractAddress.js';
|
|
78
78
|
export * from './deterministic/Map.js';
|
|
79
|
+
export * from './deterministic/CustomMap.js';
|
|
79
80
|
declare global {
|
|
80
81
|
interface Window {
|
|
81
82
|
unisat?: Unisat;
|
package/build/opnet.js
CHANGED
package/package.json
CHANGED