hypercore 10.9.1 → 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 CHANGED
@@ -123,19 +123,24 @@ class BitfieldSegment {
123
123
  findFirst (val, position) {
124
124
  position = this.tree.skipFirst(!val, position)
125
125
 
126
- const j = position & (BITS_PER_PAGE - 1)
127
- const i = (position - j) / BITS_PER_PAGE
126
+ let j = position & (BITS_PER_PAGE - 1)
127
+ let i = (position - j) / BITS_PER_PAGE
128
128
 
129
- if (i >= PAGES_PER_SEGMENT) return val ? -1 : position
129
+ if (i >= PAGES_PER_SEGMENT) return -1
130
+
131
+ while (i < this.pages.length) {
132
+ const p = this.pages[i]
130
133
 
131
- const p = this.pages[i]
134
+ let index = -1
132
135
 
133
- let index = -1
136
+ if (p) index = p.findFirst(val, j)
137
+ else if (!val) index = j
134
138
 
135
- if (p) index = p.findFirst(val, j)
136
- else if (!val) index = j
139
+ if (index !== -1) return i * BITS_PER_PAGE + index
137
140
 
138
- if (index !== -1) return i * BITS_PER_PAGE + index
141
+ j = 0
142
+ i++
143
+ }
139
144
 
140
145
  return -1
141
146
  }
@@ -143,19 +148,24 @@ class BitfieldSegment {
143
148
  findLast (val, position) {
144
149
  position = this.tree.skipLast(!val, position)
145
150
 
146
- const j = position & (BITS_PER_PAGE - 1)
147
- const i = (position - j) / BITS_PER_PAGE
151
+ let j = position & (BITS_PER_PAGE - 1)
152
+ let i = (position - j) / BITS_PER_PAGE
148
153
 
149
154
  if (i >= PAGES_PER_SEGMENT) return -1
150
155
 
151
- const p = this.pages[i]
156
+ while (i >= 0) {
157
+ const p = this.pages[i]
158
+
159
+ let index = -1
152
160
 
153
- let index = -1
161
+ if (p) index = p.findLast(val, j)
162
+ else if (!val) index = j
154
163
 
155
- if (p) index = p.findLast(val, j)
156
- else if (!val) index = j
164
+ if (index !== -1) return i * BITS_PER_PAGE + index
157
165
 
158
- if (index !== -1) return i * BITS_PER_PAGE + index
166
+ j = BITS_PER_PAGE - 1
167
+ i--
168
+ }
159
169
 
160
170
  return -1
161
171
  }
@@ -84,19 +84,24 @@ class RemoteBitfieldSegment {
84
84
  findFirst (val, position) {
85
85
  position = this.tree.skipFirst(!val, position)
86
86
 
87
- const j = position & (BITS_PER_PAGE - 1)
88
- const i = (position - j) / BITS_PER_PAGE
87
+ let j = position & (BITS_PER_PAGE - 1)
88
+ let i = (position - j) / BITS_PER_PAGE
89
89
 
90
- if (i >= PAGES_PER_SEGMENT) return val ? -1 : position
90
+ if (i >= PAGES_PER_SEGMENT) return -1
91
91
 
92
- const p = this.pages[i]
92
+ while (i < this.pages.length) {
93
+ const p = this.pages[i]
93
94
 
94
- let index = -1
95
+ let index = -1
96
+
97
+ if (p) index = p.findFirst(val, j)
98
+ else if (!val) index = j
95
99
 
96
- if (p) index = p.findFirst(val, j)
97
- else if (!val) index = j
100
+ if (index !== -1) return i * BITS_PER_PAGE + index
98
101
 
99
- if (index !== -1) return i * BITS_PER_PAGE + index
102
+ j = 0
103
+ i++
104
+ }
100
105
 
101
106
  return -1
102
107
  }
@@ -104,19 +109,24 @@ class RemoteBitfieldSegment {
104
109
  findLast (val, position) {
105
110
  position = this.tree.skipLast(!val, position)
106
111
 
107
- const j = position & (BITS_PER_PAGE - 1)
108
- const i = (position - j) / BITS_PER_PAGE
112
+ let j = position & (BITS_PER_PAGE - 1)
113
+ let i = (position - j) / BITS_PER_PAGE
109
114
 
110
- if (i >= PAGES_PER_SEGMENT) return val ? -1 : position
115
+ if (i >= PAGES_PER_SEGMENT) return -1
111
116
 
112
- const p = this.pages[i]
117
+ while (i >= 0) {
118
+ const p = this.pages[i]
119
+
120
+ let index = -1
113
121
 
114
- let index = -1
122
+ if (p) index = p.findLast(val, j)
123
+ else if (!val) index = j
115
124
 
116
- if (p) index = p.findLast(val, j)
117
- else if (!val) index = j
125
+ if (index !== -1) return i * BITS_PER_PAGE + index
118
126
 
119
- if (index !== -1) return i * BITS_PER_PAGE + index
127
+ j = BITS_PER_PAGE - 1
128
+ i--
129
+ }
120
130
 
121
131
  return -1
122
132
  }
package/lib/replicator.js CHANGED
@@ -1674,12 +1674,14 @@ function clampRange (core, r) {
1674
1674
  const start = core.bitfield.firstUnset(r.start)
1675
1675
 
1676
1676
  if (r.end === -1) r.start = start === -1 ? core.tree.length : start
1677
- else if (start === -1) r.start = r.end
1677
+ else if (start === -1 || start >= r.end) r.start = r.end
1678
1678
  else {
1679
- const end = core.bitfield.lastUnset(r.end)
1680
-
1681
1679
  r.start = start
1682
- r.end = end
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
1683
1685
  }
1684
1686
  } else {
1685
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.1",
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.1.0",
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",