hyperbee2 2.0.1 → 2.0.4
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/index.js +3 -1
- package/lib/cache.js +5 -4
- package/lib/compression.js +9 -2
- package/lib/ranges.js +13 -6
- package/lib/write.js +1 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -182,7 +182,9 @@ class Hyperbee {
|
|
|
182
182
|
children[i] = inflateChild(context, d, ptr, block, activeRequests)
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
|
|
185
|
+
const value = new TreeNode(await Promise.all(keys), await Promise.all(children))
|
|
186
|
+
if (!ptr.value) ptr.value = value
|
|
187
|
+
|
|
186
188
|
this.bump(ptr)
|
|
187
189
|
|
|
188
190
|
return ptr.value
|
package/lib/cache.js
CHANGED
|
@@ -10,10 +10,11 @@ module.exports = class NodeCache {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
empty() {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
while (this.size > 0) {
|
|
14
|
+
const old = this.oldest()
|
|
15
|
+
this.remove(old)
|
|
16
|
+
old.value = null
|
|
17
|
+
}
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
gc() {
|
package/lib/compression.js
CHANGED
|
@@ -94,7 +94,14 @@ class CompressedArray {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
flush(max, min) {
|
|
97
|
-
|
|
97
|
+
let overflow = false
|
|
98
|
+
for (const d of this.delta) {
|
|
99
|
+
if (d.index < 256) continue // has to be uint3, only happens in rebalances/splits
|
|
100
|
+
overflow = true
|
|
101
|
+
break
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (this.delta.length <= max && !overflow) return this.delta
|
|
98
105
|
|
|
99
106
|
const direct = []
|
|
100
107
|
while (this.delta.length && this.delta[this.delta.length - 1].type !== OP_COHORT) {
|
|
@@ -102,7 +109,7 @@ class CompressedArray {
|
|
|
102
109
|
}
|
|
103
110
|
direct.reverse()
|
|
104
111
|
|
|
105
|
-
if (direct.length > min && direct.length < this.entries.length) {
|
|
112
|
+
if (direct.length > min && direct.length < this.entries.length && !overflow) {
|
|
106
113
|
const co = new DeltaCohort(true, null, [])
|
|
107
114
|
for (const d of direct) {
|
|
108
115
|
co.deltas.push(d)
|
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
|
}
|
package/lib/write.js
CHANGED
|
@@ -8,7 +8,6 @@ const {
|
|
|
8
8
|
ValuePointer,
|
|
9
9
|
TreeNode,
|
|
10
10
|
TreeNodePointer,
|
|
11
|
-
MIN_KEYS,
|
|
12
11
|
INSERTED,
|
|
13
12
|
NEEDS_SPLIT
|
|
14
13
|
} = require('./tree.js')
|
|
@@ -272,7 +271,7 @@ module.exports = class WriteBatch {
|
|
|
272
271
|
|
|
273
272
|
const v = ptr.value ? this.snapshot.bump(ptr) : await this.snapshot.inflate(ptr)
|
|
274
273
|
|
|
275
|
-
if (v.keys.length >=
|
|
274
|
+
if (v.keys.length >= minKeys) return root
|
|
276
275
|
|
|
277
276
|
const p = parent.value ? this.snapshot.bump(parent) : await this.snapshot.inflate(parent)
|
|
278
277
|
|