From 88a0bb0685175b2b8ae14e3c4a3e9db1604dfd09 Mon Sep 17 00:00:00 2001 From: Christophe Diederichs Date: Wed, 30 Oct 2024 10:30:46 +0000 Subject: [PATCH] missing helper --- lib/memory-overlay.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/memory-overlay.js b/lib/memory-overlay.js index a1b0716..41bb34b 100644 --- a/lib/memory-overlay.js +++ b/lib/memory-overlay.js @@ -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 () { @@ -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)