From 131c8ad2bdf8550a09a6f887408ab502c11ff982 Mon Sep 17 00:00:00 2001 From: Jesse Wright <63333554+jeswr@users.noreply.github.com> Date: Wed, 22 May 2024 09:19:53 +0100 Subject: [PATCH] Reduce memory usage of symmetric hash join Closes #11 --- join/SymmetricHashJoin.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/join/SymmetricHashJoin.js b/join/SymmetricHashJoin.js index c102008..57efdaf 100644 --- a/join/SymmetricHashJoin.js +++ b/join/SymmetricHashJoin.js @@ -100,11 +100,18 @@ class SymmetricHashJoin extends AsyncIterator } let hash = this.funHash(item); - let map = this.usedLeft ? this.leftMap : this.rightMap; - if (!map.has(hash)) - map.set(hash, []); - let arr = map.get(hash); - arr.push(item); + + if (this.usedLeft && this.right.done) { + this.leftMap = null; + } else if (this.left.done) { + this.rightMap = null; + } else { + let map = this.usedLeft ? this.leftMap : this.rightMap; + if (!map.has(hash)) + map.set(hash, []); + let arr = map.get(hash); + arr.push(item); + } this.match = item; this.matches = (this.usedLeft ? this.rightMap : this.leftMap).get(hash) || [];