@btc-vision/transaction 1.7.5 → 1.7.7
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/_version.d.ts +1 -1
- package/browser/src/deterministic/DeterministicMap.d.ts +3 -3
- package/browser/src/deterministic/FastMap.d.ts +24 -0
- package/browser/src/opnet.d.ts +1 -1
- package/browser/test/fastmap-setall.test.d.ts +1 -0
- package/browser/test/fastmap.test.d.ts +1 -0
- package/browser/test/old/FastBigIntMap.d.ts +18 -0
- package/browser/test/oldfastmap.test.d.ts +1 -0
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/deterministic/AddressMap.js +2 -2
- package/build/deterministic/DeterministicMap.d.ts +3 -3
- package/build/deterministic/DeterministicMap.js +2 -2
- package/build/deterministic/FastMap.d.ts +24 -0
- package/build/deterministic/FastMap.js +88 -0
- package/build/opnet.d.ts +1 -1
- package/build/opnet.js +1 -1
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/deterministic/AddressMap.ts +3 -3
- package/src/deterministic/DeterministicMap.ts +9 -6
- package/src/deterministic/FastMap.ts +124 -0
- package/src/opnet.ts +1 -1
- package/test/fastmap-setall.test.ts +143 -0
- package/test/fastmap.test.ts +917 -0
- package/test/old/FastBigIntMap.ts +132 -0
- package/test/oldfastmap.test.ts +917 -0
- package/browser/src/deterministic/Map.d.ts +0 -16
- package/build/deterministic/Map.d.ts +0 -16
- package/build/deterministic/Map.js +0 -74
- package/src/deterministic/Map.ts +0 -87
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
export class FastBigIntMap {
|
|
2
|
+
private items: Record<string, bigint>;
|
|
3
|
+
private keyOrder: bigint[];
|
|
4
|
+
|
|
5
|
+
constructor(iterable?: ReadonlyArray<readonly [bigint, bigint]> | null | FastBigIntMap) {
|
|
6
|
+
this.items = {};
|
|
7
|
+
this.keyOrder = [];
|
|
8
|
+
|
|
9
|
+
if (iterable instanceof FastBigIntMap) {
|
|
10
|
+
this.setAll(iterable);
|
|
11
|
+
} else {
|
|
12
|
+
if (iterable) {
|
|
13
|
+
for (const [key, value] of iterable) {
|
|
14
|
+
this.set(key, value);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Number of entries in the map.
|
|
22
|
+
*/
|
|
23
|
+
get size(): number {
|
|
24
|
+
return this.keyOrder.length;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public setAll(map: FastBigIntMap): void {
|
|
28
|
+
this.items = { ...map.items };
|
|
29
|
+
this.keyOrder = [...map.keyOrder];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public addAll(map: FastBigIntMap): void {
|
|
33
|
+
for (const [key, value] of map.entries()) {
|
|
34
|
+
this.set(key, value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Inserts or updates the key/value. Returns `this` to allow chaining.
|
|
40
|
+
*/
|
|
41
|
+
set(key: bigint, value: bigint): this {
|
|
42
|
+
const keyStr = key.toString();
|
|
43
|
+
// If key is new, push to keyOrder
|
|
44
|
+
if (!this.has(key)) {
|
|
45
|
+
this.keyOrder.push(key);
|
|
46
|
+
}
|
|
47
|
+
// Store value in the record
|
|
48
|
+
this.items[keyStr] = value;
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Retrieves the value for the given key. Returns undefined if key not found.
|
|
54
|
+
*/
|
|
55
|
+
get(key: bigint): bigint | undefined {
|
|
56
|
+
return this.items[key.toString()];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Checks if a key exists in the map.
|
|
61
|
+
*/
|
|
62
|
+
has(key: bigint): boolean {
|
|
63
|
+
return Object.prototype.hasOwnProperty.call(this.items, key.toString());
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Deletes a key if it exists. Returns boolean indicating success.
|
|
68
|
+
*/
|
|
69
|
+
delete(key: bigint): boolean {
|
|
70
|
+
const keyStr = key.toString();
|
|
71
|
+
if (this.has(key)) {
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
73
|
+
delete this.items[keyStr];
|
|
74
|
+
// Remove from keyOrder
|
|
75
|
+
this.keyOrder = this.keyOrder.filter((k) => k !== key);
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Removes all keys and values.
|
|
83
|
+
*/
|
|
84
|
+
clear(): void {
|
|
85
|
+
this.items = {};
|
|
86
|
+
this.keyOrder = [];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Iterates over [key, value] pairs in insertion order.
|
|
91
|
+
*/
|
|
92
|
+
*entries(): IterableIterator<[bigint, bigint]> {
|
|
93
|
+
for (const key of this.keyOrder) {
|
|
94
|
+
yield [key, this.items[key.toString()]];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Iterates over keys in insertion order.
|
|
100
|
+
*/
|
|
101
|
+
*keys(): IterableIterator<bigint> {
|
|
102
|
+
yield* this.keyOrder;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Iterates over values in insertion order.
|
|
107
|
+
*/
|
|
108
|
+
*values(): IterableIterator<bigint> {
|
|
109
|
+
for (const key of this.keyOrder) {
|
|
110
|
+
yield this.items[key.toString()];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* forEach callback in insertion order, similar to JS Map.
|
|
116
|
+
*/
|
|
117
|
+
forEach(
|
|
118
|
+
callback: (value: bigint, key: bigint, map: FastBigIntMap) => void,
|
|
119
|
+
thisArg?: unknown,
|
|
120
|
+
): void {
|
|
121
|
+
for (const key of this.keyOrder) {
|
|
122
|
+
callback.call(thisArg, this.items[key.toString()], key, this);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Makes the map iterable with `for...of`, yielding [key, value] pairs.
|
|
128
|
+
*/
|
|
129
|
+
[Symbol.iterator](): IterableIterator<[bigint, bigint]> {
|
|
130
|
+
return this.entries();
|
|
131
|
+
}
|
|
132
|
+
}
|