hypercore 10.9.0 → 10.9.1

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
@@ -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]
@@ -126,17 +126,16 @@ class BitfieldSegment {
126
126
  const j = position & (BITS_PER_PAGE - 1)
127
127
  const i = (position - j) / BITS_PER_PAGE
128
128
 
129
- if (i >= PAGES_PER_SEGMENT) return -1
129
+ if (i >= PAGES_PER_SEGMENT) return val ? -1 : position
130
130
 
131
131
  const p = this.pages[i]
132
132
 
133
- if (p) {
134
- const index = p.findFirst(val, j)
133
+ let index = -1
135
134
 
136
- if (index !== -1) {
137
- return i * BITS_PER_PAGE + index
138
- }
139
- }
135
+ if (p) index = p.findFirst(val, j)
136
+ else if (!val) index = j
137
+
138
+ if (index !== -1) return i * BITS_PER_PAGE + index
140
139
 
141
140
  return -1
142
141
  }
@@ -151,13 +150,12 @@ class BitfieldSegment {
151
150
 
152
151
  const p = this.pages[i]
153
152
 
154
- if (p) {
155
- const index = p.findLast(val, j)
153
+ let index = -1
156
154
 
157
- if (index !== -1) {
158
- return i * BITS_PER_PAGE + index
159
- }
160
- }
155
+ if (p) index = p.findLast(val, j)
156
+ else if (!val) index = j
157
+
158
+ if (index !== -1) return i * BITS_PER_PAGE + index
161
159
 
162
160
  return -1
163
161
  }
@@ -276,19 +274,18 @@ module.exports = class Bitfield {
276
274
  while (i < this._segments.maxLength) {
277
275
  const s = this._segments.get(i)
278
276
 
279
- if (s) {
280
- const index = s.findFirst(val, j)
277
+ let index = -1
281
278
 
282
- if (index !== -1) {
283
- return i * BITS_PER_SEGMENT + index
284
- }
285
- }
279
+ if (s) index = s.findFirst(val, j)
280
+ else if (!val) index = j
281
+
282
+ if (index !== -1) return i * BITS_PER_SEGMENT + index
286
283
 
287
284
  j = 0
288
285
  i++
289
286
  }
290
287
 
291
- return -1
288
+ return val ? -1 : position
292
289
  }
293
290
 
294
291
  firstSet (position) {
@@ -306,13 +303,12 @@ module.exports = class Bitfield {
306
303
  while (i >= 0) {
307
304
  const s = this._segments.get(i)
308
305
 
309
- if (s) {
310
- const index = s.findLast(val, j)
306
+ let index = -1
311
307
 
312
- if (index !== -1) {
313
- return i * BITS_PER_SEGMENT + index
314
- }
315
- }
308
+ if (s) index = s.findLast(val, j)
309
+ else if (!val) index = j
310
+
311
+ if (index !== -1) return i * BITS_PER_SEGMENT + index
316
312
 
317
313
  j = BITS_PER_SEGMENT - 1
318
314
  i--
@@ -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
 
@@ -87,17 +87,16 @@ class RemoteBitfieldSegment {
87
87
  const j = position & (BITS_PER_PAGE - 1)
88
88
  const i = (position - j) / BITS_PER_PAGE
89
89
 
90
- if (i >= PAGES_PER_SEGMENT) return -1
90
+ if (i >= PAGES_PER_SEGMENT) return val ? -1 : position
91
91
 
92
92
  const p = this.pages[i]
93
93
 
94
- if (p) {
95
- const index = p.findFirst(val, j)
94
+ let index = -1
96
95
 
97
- if (index !== -1) {
98
- return i * BITS_PER_PAGE + index
99
- }
100
- }
96
+ if (p) index = p.findFirst(val, j)
97
+ else if (!val) index = j
98
+
99
+ if (index !== -1) return i * BITS_PER_PAGE + index
101
100
 
102
101
  return -1
103
102
  }
@@ -108,17 +107,16 @@ class RemoteBitfieldSegment {
108
107
  const j = position & (BITS_PER_PAGE - 1)
109
108
  const i = (position - j) / BITS_PER_PAGE
110
109
 
111
- if (i >= PAGES_PER_SEGMENT) return -1
110
+ if (i >= PAGES_PER_SEGMENT) return val ? -1 : position
112
111
 
113
112
  const p = this.pages[i]
114
113
 
115
- if (p) {
116
- const index = p.findLast(val, j)
114
+ let index = -1
117
115
 
118
- if (index !== -1) {
119
- return i * BITS_PER_PAGE + index
120
- }
121
- }
116
+ if (p) index = p.findLast(val, j)
117
+ else if (!val) index = j
118
+
119
+ if (index !== -1) return i * BITS_PER_PAGE + index
122
120
 
123
121
  return -1
124
122
  }
@@ -187,19 +185,18 @@ module.exports = class RemoteBitfield {
187
185
  while (i < this._segments.maxLength) {
188
186
  const s = this._segments.get(i)
189
187
 
190
- if (s) {
191
- const index = s.findFirst(val, j)
188
+ let index = -1
192
189
 
193
- if (index !== -1) {
194
- return i * BITS_PER_SEGMENT + index
195
- }
196
- }
190
+ if (s) index = s.findFirst(val, j)
191
+ else if (!val) index = j
192
+
193
+ if (index !== -1) return i * BITS_PER_SEGMENT + index
197
194
 
198
195
  j = 0
199
196
  i++
200
197
  }
201
198
 
202
- return -1
199
+ return val ? -1 : position
203
200
  }
204
201
 
205
202
  firstSet (position) {
@@ -217,13 +214,12 @@ module.exports = class RemoteBitfield {
217
214
  while (i >= 0) {
218
215
  const s = this._segments.get(i)
219
216
 
220
- if (s) {
221
- const index = s.findLast(val, j)
217
+ let index = -1
222
218
 
223
- if (index !== -1) {
224
- return i * BITS_PER_SEGMENT + index
225
- }
226
- }
219
+ if (s) index = s.findLast(val, j)
220
+ else if (!val) index = j
221
+
222
+ if (index !== -1) return i * BITS_PER_SEGMENT + index
227
223
 
228
224
  j = BITS_PER_SEGMENT - 1
229
225
  i--
package/lib/replicator.js CHANGED
@@ -1673,17 +1673,13 @@ 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
- r.start = start === -1 ? core.tree.length : start
1678
- } else {
1679
- const end = core.bitfield.lastUnset(r.end - 1) + 1
1680
-
1681
- if (start === -1) {
1682
- r.start = r.end
1683
- } else {
1684
- r.start = start
1685
- r.end = end
1686
- }
1676
+ if (r.end === -1) r.start = start === -1 ? core.tree.length : start
1677
+ else if (start === -1) r.start = r.end
1678
+ else {
1679
+ const end = core.bitfield.lastUnset(r.end)
1680
+
1681
+ r.start = start
1682
+ r.end = end
1687
1683
  }
1688
1684
  } else {
1689
1685
  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.0",
3
+ "version": "10.9.1",
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.0.3",
46
+ "quickbit-universal": "^2.1.0",
47
47
  "random-access-file": "^4.0.0",
48
48
  "random-array-iterator": "^1.0.0",
49
49
  "safety-catch": "^1.0.1",