Skip to content

Commit

Permalink
Add memoization to provider functions
Browse files Browse the repository at this point in the history
  • Loading branch information
amshenoy committed Oct 19, 2023
1 parent babee8b commit 454e604
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions assets/js/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,16 @@ function II(F, S, Nf, Ns) {
}


const mHL = memoize(HL)
const mAJB = memoize(AJB)
const mBARC = memoize(BARC)
const mFID = memoize(FID)
const mII = memoize(II)
const mMIN = memoize(MIN)


function MIN(f, s, Nf, Ns) {
var providers = [HL, AJB, BARC, FID, II]
var providers = [mHL, mAJB, mBARC, mFID, mII]
var arr = []
for (let provider of providers) {
arr.push(provider(f, s, Nf, Ns))
Expand All @@ -147,11 +155,20 @@ function MIN(f, s, Nf, Ns) {
}


function memoize(fn) {
const cache = new Map();
return (...args) => {
const key = JSON.stringify(args);
return cache.has(key) ? cache.get(key) : cache.set(key, fn(...args)).get(key);
}
}


const PROVIDERS = {
"HL": HL,
"AJB": AJB,
"BARC": BARC,
"FID": FID,
"II": II,
"MIN": MIN
"HL": mHL,
"AJB": mAJB,
"BARC": mBARC,
"FID": mFID,
"II": mII,
"MIN": mMIN,
}

0 comments on commit 454e604

Please sign in to comment.