hypercore 10.9.0 → 10.9.2
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/lib/bitfield.js +37 -31
- package/lib/remote-bitfield.js +36 -30
- package/lib/replicator.js +9 -11
- package/package.json +2 -2
package/lib/bitfield.js
CHANGED
|
@@ -80,7 +80,7 @@ class BitfieldSegment {
|
|
|
80
80
|
constructor (index, bitfield) {
|
|
81
81
|
this.index = index
|
|
82
82
|
this.offset = index * BYTES_PER_SEGMENT
|
|
83
|
-
this.tree = quickbit.Index.from(bitfield)
|
|
83
|
+
this.tree = quickbit.Index.from(bitfield, BYTES_PER_SEGMENT)
|
|
84
84
|
this.pages = new Array(PAGES_PER_SEGMENT)
|
|
85
85
|
}
|
|
86
86
|
|
|
@@ -107,7 +107,7 @@ class BitfieldSegment {
|
|
|
107
107
|
const bitfield = new Uint32Array(target)
|
|
108
108
|
bitfield.set(this.bitfield)
|
|
109
109
|
|
|
110
|
-
this.tree = quickbit.Index.from(bitfield)
|
|
110
|
+
this.tree = quickbit.Index.from(bitfield, BYTES_PER_SEGMENT)
|
|
111
111
|
|
|
112
112
|
for (let i = 0; i < this.pages.length; i++) {
|
|
113
113
|
const page = this.pages[i]
|
|
@@ -123,19 +123,23 @@ class BitfieldSegment {
|
|
|
123
123
|
findFirst (val, position) {
|
|
124
124
|
position = this.tree.skipFirst(!val, position)
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
let j = position & (BITS_PER_PAGE - 1)
|
|
127
|
+
let i = (position - j) / BITS_PER_PAGE
|
|
128
128
|
|
|
129
129
|
if (i >= PAGES_PER_SEGMENT) return -1
|
|
130
130
|
|
|
131
|
-
|
|
131
|
+
while (i < this.pages.length) {
|
|
132
|
+
const p = this.pages[i]
|
|
132
133
|
|
|
133
|
-
|
|
134
|
-
const index = p.findFirst(val, j)
|
|
134
|
+
let index = -1
|
|
135
135
|
|
|
136
|
-
if (index
|
|
137
|
-
|
|
138
|
-
|
|
136
|
+
if (p) index = p.findFirst(val, j)
|
|
137
|
+
else if (!val) index = j
|
|
138
|
+
|
|
139
|
+
if (index !== -1) return i * BITS_PER_PAGE + index
|
|
140
|
+
|
|
141
|
+
j = 0
|
|
142
|
+
i++
|
|
139
143
|
}
|
|
140
144
|
|
|
141
145
|
return -1
|
|
@@ -144,19 +148,23 @@ class BitfieldSegment {
|
|
|
144
148
|
findLast (val, position) {
|
|
145
149
|
position = this.tree.skipLast(!val, position)
|
|
146
150
|
|
|
147
|
-
|
|
148
|
-
|
|
151
|
+
let j = position & (BITS_PER_PAGE - 1)
|
|
152
|
+
let i = (position - j) / BITS_PER_PAGE
|
|
149
153
|
|
|
150
154
|
if (i >= PAGES_PER_SEGMENT) return -1
|
|
151
155
|
|
|
152
|
-
|
|
156
|
+
while (i >= 0) {
|
|
157
|
+
const p = this.pages[i]
|
|
153
158
|
|
|
154
|
-
|
|
155
|
-
const index = p.findLast(val, j)
|
|
159
|
+
let index = -1
|
|
156
160
|
|
|
157
|
-
if (index
|
|
158
|
-
|
|
159
|
-
|
|
161
|
+
if (p) index = p.findLast(val, j)
|
|
162
|
+
else if (!val) index = j
|
|
163
|
+
|
|
164
|
+
if (index !== -1) return i * BITS_PER_PAGE + index
|
|
165
|
+
|
|
166
|
+
j = BITS_PER_PAGE - 1
|
|
167
|
+
i--
|
|
160
168
|
}
|
|
161
169
|
|
|
162
170
|
return -1
|
|
@@ -276,19 +284,18 @@ module.exports = class Bitfield {
|
|
|
276
284
|
while (i < this._segments.maxLength) {
|
|
277
285
|
const s = this._segments.get(i)
|
|
278
286
|
|
|
279
|
-
|
|
280
|
-
const index = s.findFirst(val, j)
|
|
287
|
+
let index = -1
|
|
281
288
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
289
|
+
if (s) index = s.findFirst(val, j)
|
|
290
|
+
else if (!val) index = j
|
|
291
|
+
|
|
292
|
+
if (index !== -1) return i * BITS_PER_SEGMENT + index
|
|
286
293
|
|
|
287
294
|
j = 0
|
|
288
295
|
i++
|
|
289
296
|
}
|
|
290
297
|
|
|
291
|
-
return -1
|
|
298
|
+
return val ? -1 : position
|
|
292
299
|
}
|
|
293
300
|
|
|
294
301
|
firstSet (position) {
|
|
@@ -306,13 +313,12 @@ module.exports = class Bitfield {
|
|
|
306
313
|
while (i >= 0) {
|
|
307
314
|
const s = this._segments.get(i)
|
|
308
315
|
|
|
309
|
-
|
|
310
|
-
const index = s.findLast(val, j)
|
|
316
|
+
let index = -1
|
|
311
317
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
318
|
+
if (s) index = s.findLast(val, j)
|
|
319
|
+
else if (!val) index = j
|
|
320
|
+
|
|
321
|
+
if (index !== -1) return i * BITS_PER_SEGMENT + index
|
|
316
322
|
|
|
317
323
|
j = BITS_PER_SEGMENT - 1
|
|
318
324
|
i--
|
package/lib/remote-bitfield.js
CHANGED
|
@@ -58,7 +58,7 @@ class RemoteBitfieldSegment {
|
|
|
58
58
|
constructor (index) {
|
|
59
59
|
this.index = index
|
|
60
60
|
this.offset = index * BYTES_PER_SEGMENT
|
|
61
|
-
this.tree = quickbit.Index.from([])
|
|
61
|
+
this.tree = quickbit.Index.from([], BYTES_PER_SEGMENT)
|
|
62
62
|
this.pages = new Array(PAGES_PER_SEGMENT)
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -84,19 +84,23 @@ class RemoteBitfieldSegment {
|
|
|
84
84
|
findFirst (val, position) {
|
|
85
85
|
position = this.tree.skipFirst(!val, position)
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
let j = position & (BITS_PER_PAGE - 1)
|
|
88
|
+
let i = (position - j) / BITS_PER_PAGE
|
|
89
89
|
|
|
90
90
|
if (i >= PAGES_PER_SEGMENT) return -1
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
while (i < this.pages.length) {
|
|
93
|
+
const p = this.pages[i]
|
|
93
94
|
|
|
94
|
-
|
|
95
|
-
const index = p.findFirst(val, j)
|
|
95
|
+
let index = -1
|
|
96
96
|
|
|
97
|
-
if (index
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
if (p) index = p.findFirst(val, j)
|
|
98
|
+
else if (!val) index = j
|
|
99
|
+
|
|
100
|
+
if (index !== -1) return i * BITS_PER_PAGE + index
|
|
101
|
+
|
|
102
|
+
j = 0
|
|
103
|
+
i++
|
|
100
104
|
}
|
|
101
105
|
|
|
102
106
|
return -1
|
|
@@ -105,19 +109,23 @@ class RemoteBitfieldSegment {
|
|
|
105
109
|
findLast (val, position) {
|
|
106
110
|
position = this.tree.skipLast(!val, position)
|
|
107
111
|
|
|
108
|
-
|
|
109
|
-
|
|
112
|
+
let j = position & (BITS_PER_PAGE - 1)
|
|
113
|
+
let i = (position - j) / BITS_PER_PAGE
|
|
110
114
|
|
|
111
115
|
if (i >= PAGES_PER_SEGMENT) return -1
|
|
112
116
|
|
|
113
|
-
|
|
117
|
+
while (i >= 0) {
|
|
118
|
+
const p = this.pages[i]
|
|
119
|
+
|
|
120
|
+
let index = -1
|
|
114
121
|
|
|
115
|
-
|
|
116
|
-
|
|
122
|
+
if (p) index = p.findLast(val, j)
|
|
123
|
+
else if (!val) index = j
|
|
117
124
|
|
|
118
|
-
if (index !== -1)
|
|
119
|
-
|
|
120
|
-
|
|
125
|
+
if (index !== -1) return i * BITS_PER_PAGE + index
|
|
126
|
+
|
|
127
|
+
j = BITS_PER_PAGE - 1
|
|
128
|
+
i--
|
|
121
129
|
}
|
|
122
130
|
|
|
123
131
|
return -1
|
|
@@ -187,19 +195,18 @@ module.exports = class RemoteBitfield {
|
|
|
187
195
|
while (i < this._segments.maxLength) {
|
|
188
196
|
const s = this._segments.get(i)
|
|
189
197
|
|
|
190
|
-
|
|
191
|
-
const index = s.findFirst(val, j)
|
|
198
|
+
let index = -1
|
|
192
199
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
200
|
+
if (s) index = s.findFirst(val, j)
|
|
201
|
+
else if (!val) index = j
|
|
202
|
+
|
|
203
|
+
if (index !== -1) return i * BITS_PER_SEGMENT + index
|
|
197
204
|
|
|
198
205
|
j = 0
|
|
199
206
|
i++
|
|
200
207
|
}
|
|
201
208
|
|
|
202
|
-
return -1
|
|
209
|
+
return val ? -1 : position
|
|
203
210
|
}
|
|
204
211
|
|
|
205
212
|
firstSet (position) {
|
|
@@ -217,13 +224,12 @@ module.exports = class RemoteBitfield {
|
|
|
217
224
|
while (i >= 0) {
|
|
218
225
|
const s = this._segments.get(i)
|
|
219
226
|
|
|
220
|
-
|
|
221
|
-
const index = s.findLast(val, j)
|
|
227
|
+
let index = -1
|
|
222
228
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
229
|
+
if (s) index = s.findLast(val, j)
|
|
230
|
+
else if (!val) index = j
|
|
231
|
+
|
|
232
|
+
if (index !== -1) return i * BITS_PER_SEGMENT + index
|
|
227
233
|
|
|
228
234
|
j = BITS_PER_SEGMENT - 1
|
|
229
235
|
i--
|
package/lib/replicator.js
CHANGED
|
@@ -1673,17 +1673,15 @@ function clampRange (core, r) {
|
|
|
1673
1673
|
if (r.blocks === null) {
|
|
1674
1674
|
const start = core.bitfield.firstUnset(r.start)
|
|
1675
1675
|
|
|
1676
|
-
if (r.end === -1)
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
r.end = end
|
|
1686
|
-
}
|
|
1676
|
+
if (r.end === -1) r.start = start === -1 ? core.tree.length : start
|
|
1677
|
+
else if (start === -1 || start >= r.end) r.start = r.end
|
|
1678
|
+
else {
|
|
1679
|
+
r.start = start
|
|
1680
|
+
|
|
1681
|
+
const end = core.bitfield.lastUnset(r.end - 1)
|
|
1682
|
+
|
|
1683
|
+
if (end === -1 || start >= end + 1) r.end = r.start
|
|
1684
|
+
else r.end = end + 1
|
|
1687
1685
|
}
|
|
1688
1686
|
} else {
|
|
1689
1687
|
while (r.start < r.end && core.bitfield.get(r.blocks[r.start])) r.start++
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hypercore",
|
|
3
|
-
"version": "10.9.
|
|
3
|
+
"version": "10.9.2",
|
|
4
4
|
"description": "Hypercore is a secure, distributed append-only log",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"hypercore-crypto": "^3.2.1",
|
|
44
44
|
"is-options": "^1.0.1",
|
|
45
45
|
"protomux": "^3.4.0",
|
|
46
|
-
"quickbit-universal": "^2.
|
|
46
|
+
"quickbit-universal": "^2.1.1",
|
|
47
47
|
"random-access-file": "^4.0.0",
|
|
48
48
|
"random-array-iterator": "^1.0.0",
|
|
49
49
|
"safety-catch": "^1.0.1",
|