hypercore 11.37.0 → 11.37.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.
@@ -153,6 +153,7 @@ module.exports = class RemoteBitfield {
153
153
  this._pages = new BigSparseArray()
154
154
  this._segments = new BigSparseArray()
155
155
  this._maxSegments = 0
156
+ this._maxPages = 0
156
157
  }
157
158
 
158
159
  getBitfield(index) {
@@ -182,6 +183,7 @@ module.exports = class RemoteBitfield {
182
183
  const k = Math.floor(i / PAGES_PER_SEGMENT)
183
184
  const s = this._segments.get(k) || this._segments.set(k, new RemoteBitfieldSegment(k))
184
185
  if (this._maxSegments <= k) this._maxSegments = k + 1
186
+ if (this._maxPages <= i) this._maxPages = i + 1
185
187
 
186
188
  p = this._pages.set(i, new RemoteBitfieldPage(i, new Uint32Array(WORDS_PER_PAGE), s))
187
189
  }
@@ -193,6 +195,9 @@ module.exports = class RemoteBitfield {
193
195
  let j = start & (BITS_PER_PAGE - 1)
194
196
  let i = (start - j) / BITS_PER_PAGE
195
197
 
198
+ // Cap end if val = false
199
+ if (!val) end = Math.min(end, this._maxPages * BITS_PER_PAGE)
200
+
196
201
  while (start < end) {
197
202
  let p = this._pages.get(i)
198
203
 
@@ -200,6 +205,7 @@ module.exports = class RemoteBitfield {
200
205
  const k = Math.floor(i / PAGES_PER_SEGMENT)
201
206
  const s = this._segments.get(k) || this._segments.set(k, new RemoteBitfieldSegment(k))
202
207
  if (this._maxSegments <= k) this._maxSegments = k + 1
208
+ if (this._maxPages <= i) this._maxPages = i + 1
203
209
 
204
210
  p = this._pages.set(i, new RemoteBitfieldPage(i, new Uint32Array(WORDS_PER_PAGE), s))
205
211
  }
@@ -251,6 +257,8 @@ module.exports = class RemoteBitfield {
251
257
  let j = position & (BITS_PER_SEGMENT - 1)
252
258
  let i = (position - j) / BITS_PER_SEGMENT
253
259
 
260
+ if (i >= this._maxSegments) return -1
261
+
254
262
  while (i >= 0) {
255
263
  const s = this._segments.get(i)
256
264
 
@@ -291,6 +299,7 @@ module.exports = class RemoteBitfield {
291
299
  const k = Math.floor(i / PAGES_PER_SEGMENT)
292
300
  const s = this._segments.get(k) || this._segments.set(k, new RemoteBitfieldSegment(k))
293
301
  if (this._maxSegments <= k) this._maxSegments = k + 1
302
+ if (this._maxPages <= i) this._maxPages = i + 1
294
303
 
295
304
  p = this._pages.set(i, new RemoteBitfieldPage(i, new Uint32Array(WORDS_PER_PAGE), s))
296
305
  }
@@ -319,20 +328,11 @@ module.exports = class RemoteBitfield {
319
328
  let i = (start - j) / BITS_PER_PAGE
320
329
 
321
330
  while (length > 0) {
322
- let p = this._pages.get(i)
323
-
324
- if (!p) {
325
- const k = Math.floor(i / PAGES_PER_SEGMENT)
326
- const s = this._segments.get(k) || this._segments.set(k, new RemoteBitfieldSegment(k))
327
- if (this._maxSegments <= k) this._maxSegments = k + 1
328
-
329
- p = this._pages.set(i, new RemoteBitfieldPage(i, new Uint32Array(WORDS_PER_PAGE), s))
330
- }
331
-
331
+ const p = this._pages.get(i)
332
332
  const end = Math.min(j + length, BITS_PER_PAGE)
333
333
  const range = end - j
334
334
 
335
- p.clear(j, bitfield.subarray(0, range / 32))
335
+ if (p) p.clear(j, bitfield.subarray(0, range / 32))
336
336
 
337
337
  bitfield = bitfield.subarray(range / 32)
338
338
 
@@ -570,7 +570,7 @@ class SessionState {
570
570
  const [left, right] = flat.spans(b)
571
571
  const s = left / 2
572
572
  const e = right / 2 + 1
573
- const has = s <= start && e <= end ? false : this.core.bitfield.hasSet(s, e - s)
573
+ const has = s >= start && e <= end ? false : this.core.bitfield.hasSet(s, e - s)
574
574
  if (has) break
575
575
 
576
576
  tx.deleteTreeNode(a)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "11.37.0",
3
+ "version": "11.37.2",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {