hypercore 11.15.0 → 11.16.0

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 CHANGED
@@ -400,6 +400,30 @@ module.exports = class Bitfield {
400
400
  return this.findLast(false, position)
401
401
  }
402
402
 
403
+ hasSet (start, length) {
404
+ const end = start + length
405
+
406
+ let j = start & (BITS_PER_SEGMENT - 1)
407
+ let i = (start - j) / BITS_PER_SEGMENT
408
+
409
+ while (i < this._segments.maxLength) {
410
+ const s = this._segments.get(i)
411
+
412
+ let index = -1
413
+
414
+ if (s) index = s.findFirst(true, j)
415
+
416
+ if (index !== -1) return (i * BITS_PER_SEGMENT + index) < end
417
+
418
+ j = 0
419
+ i++
420
+
421
+ if (i * BITS_PER_SEGMENT >= end) return false
422
+ }
423
+
424
+ return false
425
+ }
426
+
403
427
  count (start, length, val) {
404
428
  let j = start & (BITS_PER_PAGE - 1)
405
429
  let i = (start - j) / BITS_PER_PAGE
@@ -476,6 +476,22 @@ module.exports = class SessionState {
476
476
  try {
477
477
  const tx = this.createWriteBatch()
478
478
 
479
+ const ite = flat.iterator(start * 2)
480
+ while (!isRootIndex(ite.index, this.roots)) {
481
+ const a = ite.index
482
+ const b = ite.sibling()
483
+ ite.parent()
484
+
485
+ const [left, right] = flat.spans(b)
486
+ const s = left / 2
487
+ const e = (right / 2) + 1
488
+ const has = (s <= start && e <= end) ? false : this.core.bitfield.hasSet(s, e - s)
489
+ if (has) break
490
+
491
+ tx.deleteTreeNode(a)
492
+ tx.deleteTreeNode(b)
493
+ }
494
+
479
495
  if (this.isDefault()) {
480
496
  await storeBitfieldRange(this.storage, tx, start, end, false)
481
497
  if (start < this.core.header.hints.contiguousLength) {
@@ -1134,3 +1150,11 @@ function getCoreHead (storage) {
1134
1150
  b.tryFlush()
1135
1151
  return p
1136
1152
  }
1153
+
1154
+ function isRootIndex (index, roots) {
1155
+ for (const node of roots) {
1156
+ if (node.index === index) return true
1157
+ }
1158
+
1159
+ return false
1160
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "11.15.0",
3
+ "version": "11.16.0",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {