hyperbee2 2.0.1 → 2.0.3
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/ranges.js +13 -6
- package/package.json +1 -1
package/lib/ranges.js
CHANGED
|
@@ -24,7 +24,8 @@ class RangeIterator {
|
|
|
24
24
|
this.end = lte || lt || null
|
|
25
25
|
this.inclusive = !!(reverse ? lte : gte)
|
|
26
26
|
this.compare = (reverse ? gte : lte) ? 0 : -1
|
|
27
|
-
this.
|
|
27
|
+
this.prefetch = prefetch
|
|
28
|
+
this.prefetching = null
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
async open() {
|
|
@@ -112,7 +113,7 @@ class RangeIterator {
|
|
|
112
113
|
|
|
113
114
|
if (c > this.compare) break
|
|
114
115
|
|
|
115
|
-
if (this.
|
|
116
|
+
if (this.prefetch && !v.children.length && this.stack.length) this.prefetchNext()
|
|
116
117
|
|
|
117
118
|
this.stack.push(top)
|
|
118
119
|
if (this.limit !== -1) this.limit--
|
|
@@ -123,14 +124,17 @@ class RangeIterator {
|
|
|
123
124
|
return null
|
|
124
125
|
}
|
|
125
126
|
|
|
126
|
-
|
|
127
|
+
prefetchNext() {
|
|
127
128
|
// TODO: dbl check this for off-by-ones with the offset and keys and children
|
|
128
|
-
|
|
129
|
-
|
|
129
|
+
let limit = this.limit
|
|
130
|
+
|
|
131
|
+
if (limit < this.tree.context.minKeys) return
|
|
130
132
|
|
|
131
133
|
const parent = this.stack[this.stack.length - 1]
|
|
132
134
|
const pv = parent.node.value
|
|
133
|
-
if (!pv) return
|
|
135
|
+
if (!pv || pv === this.prefetching) return
|
|
136
|
+
|
|
137
|
+
this.prefetching = pv
|
|
134
138
|
|
|
135
139
|
for (let i = parent.offset >> 1; i < pv.children.length; i++) {
|
|
136
140
|
const k = pv.keys.get(i)
|
|
@@ -147,6 +151,9 @@ class RangeIterator {
|
|
|
147
151
|
|
|
148
152
|
const c = pv.children.get(i)
|
|
149
153
|
if (!c.value) this.tree.inflate(c, this.activeRequests).catch(noop)
|
|
154
|
+
|
|
155
|
+
limit = Math.max(limit - this.tree.context.minKeys, 0)
|
|
156
|
+
if (limit === 0) break
|
|
150
157
|
}
|
|
151
158
|
}
|
|
152
159
|
}
|