Skip to content

Commit

Permalink
missing helper
Browse files Browse the repository at this point in the history
  • Loading branch information
chm-diederichs committed Oct 30, 2024
1 parent cadcdd2 commit 88a0bb0
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/memory-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@ class MemoryOverlay {

async peekLastTreeNode () {
const mem = this.treeNodes === null ? null : findHighest(this.treeNodes)

const node = mem.valid ? mem.value : null
const disk = await this.storage.peekLastTreeNode()

return (node && (!disk || node.index > disk.index)) ? node : disk
return (mem && (!disk || mem.index > disk.index)) ? mem : disk
}

async peekLastBitfieldPage () {
Expand Down Expand Up @@ -273,6 +271,17 @@ class MemoryOverlayWriteBatch {
}
}

function findHighest (map) {
let node = null

for (const t of map.values()) {
if (node && t.index < node.index) continue
node = t
}

return node
}

function mergeMap (a, b) {
if (a === null) return b
for (const [key, value] of b) a.set(key, value)
Expand Down

0 comments on commit 88a0bb0

Please sign in to comment.