{"version":3,"sources":["https://lively-kernel.org/lively4/composed-offset/src/client/reactive/active-expression-rewriting/dual-key-map.js"],"names":["DualKeyMap","constructor","_leftToMiddle","Map","add","primaryKey","secondaryKey","value","getOrCreate","remove","hasPrimary","getMiddles","_middleToRight","delete","removeSecondary","has","size","clear","get","undefined","creatorFunction","allValues","values","flatMap","inner"],"mappings":";;;;;;;;AAAe,YAAMA,UAAN,CAAiB;;AAE9BC,sBAAc;AACZ,eAAKC,aAAL,GAAqB,IAAIC,GAAJ,EAArB;AACD;;AAEDC,YAAIC,UAAJ,EAAgBC,YAAhB,EAA8BC,KAA9B,EAAqC;AACnC,eAAKC,WAAL,CAAiBH,UAAjB,EAA6BC,YAA7B,EAA2C,MAAMC,KAAjD;AACD;;AAEDE,eAAOJ,UAAP,EAAmB;AACjB,cAAG,CAAC,KAAKK,UAAL,CAAgBL,UAAhB,CAAJ,EAAiC;AACjC,eAAI,MAAMC,YAAV,IAA0B,KAAKK,UAAL,CAAgBN,UAAhB,CAA1B,EAAuD;AACrD,iBAAKO,cAAL,CAAoBC,MAApB,CAA2BP,YAA3B;AACD;AACD,eAAKJ,aAAL,CAAmBW,MAAnB,CAA0BR,UAA1B;AACD;;AAEDS,wBAAgBT,UAAhB,EAA4BC,YAA5B,EAA0C;AACxC,cAAG,CAAC,KAAKS,GAAL,CAASV,UAAT,EAAqBC,YAArB,CAAJ,EAAwC;AACxC,eAAKK,UAAL,CAAgBN,UAAhB,EAA4BQ,MAA5B,CAAmCP,YAAnC;AACA,cAAG,KAAKK,UAAL,CAAgBN,UAAhB,EAA4BW,IAA5B,KAAqC,CAAxC,EAA2C;AACzC,iBAAKd,aAAL,CAAmBW,MAAnB,CAA0BR,UAA1B;AACD;AACF;;AAEDY,gBAAQ;AACN,eAAKf,aAAL,CAAmBe,KAAnB;AACD;;AAEDP,mBAAWL,UAAX,EAAuB;AACrB,iBAAO,KAAKH,aAAL,CAAmBa,GAAnB,CAAuBV,UAAvB,CAAP;AACD;;AAEDU,YAAIV,UAAJ,EAAgBC,YAAhB,EAA8B;AAC5B,cAAG,CAAC,KAAKI,UAAL,CAAgBL,UAAhB,CAAJ,EAAiC,OAAO,KAAP;AACjC,iBAAO,KAAKM,UAAL,CAAgBN,UAAhB,EAA4BU,GAA5B,CAAgCT,YAAhC,CAAP;AACD;;AAEDK,mBAAWN,UAAX,EAAuB;AACrB,iBAAO,KAAKH,aAAL,CAAmBgB,GAAnB,CAAuBb,UAAvB,CAAP;AACD;;AAEDa,YAAIb,UAAJ,EAAgBC,YAAhB,EAA8B;AAC5B,cAAG,CAAC,KAAKS,GAAL,CAASV,UAAT,EAAqBC,YAArB,CAAJ,EAAwC,OAAOa,SAAP;AACxC,iBAAO,KAAKjB,aAAL,CAAmBgB,GAAnB,CAAuBb,UAAvB,EAAmCa,GAAnC,CAAuCZ,YAAvC,CAAP;AACD;;AAEDE,oBAAYH,UAAZ,EAAwBC,YAAxB,EAAsCc,eAAtC,EAAuD;AACrD,iBAAO,KAAKlB,aAAL,CACJM,WADI,CACQH,UADR,EACoB,MAAM,IAAIF,GAAJ,EAD1B,EAEJK,WAFI,CAEQF,YAFR,EAEsBc,eAFtB,CAAP;AAGD;;AAEDC,oBAAY;AACV,iBAAO,CAAC,GAAG,KAAKnB,aAAL,CAAmBoB,MAAnB,EAAJ,EAAiCC,OAAjC,CAAyCC,SAAS,CAAC,GAAGA,MAAMF,MAAN,EAAJ,CAAlD,CAAP;AACD;;AAxD6B;;yBAAXtB,U;;;;;;;;6BAAAA,2C","file":"dual-key-map.js","sourcesContent":["export default class DualKeyMap {\n\n  constructor() {\n    this._leftToMiddle = new Map();\n  }\n  \n  add(primaryKey, secondaryKey, value) {\n    this.getOrCreate(primaryKey, secondaryKey, () => value);\n  }\n\n  remove(primaryKey) {\n    if(!this.hasPrimary(primaryKey)) return;\n    for(const secondaryKey of this.getMiddles(primaryKey)) {\n      this._middleToRight.delete(secondaryKey);      \n    }\n    this._leftToMiddle.delete(primaryKey);\n  }\n\n  removeSecondary(primaryKey, secondaryKey) {\n    if(!this.has(primaryKey, secondaryKey)) return;\n    this.getMiddles(primaryKey).delete(secondaryKey);\n    if(this.getMiddles(primaryKey).size === 0) {\n      this._leftToMiddle.delete(primaryKey);\n    }\n  }\n\n  clear() {\n    this._leftToMiddle.clear();\n  }\n\n  hasPrimary(primaryKey) {\n    return this._leftToMiddle.has(primaryKey);\n  }\n  \n  has(primaryKey, secondaryKey) {\n    if(!this.hasPrimary(primaryKey)) return false;    \n    return this.getMiddles(primaryKey).has(secondaryKey);\n  }\n  \n  getMiddles(primaryKey) {\n    return this._leftToMiddle.get(primaryKey);\n  }\n\n  get(primaryKey, secondaryKey) {\n    if(!this.has(primaryKey, secondaryKey)) return undefined;\n    return this._leftToMiddle.get(primaryKey).get(secondaryKey);\n  }\n  \n  getOrCreate(primaryKey, secondaryKey, creatorFunction) {\n    return this._leftToMiddle\n      .getOrCreate(primaryKey, () => new Map())\n      .getOrCreate(secondaryKey, creatorFunction);\n  }\n  \n  allValues() {\n    return [...this._leftToMiddle.values()].flatMap(inner => [...inner.values()]);\n  }\n  \n}\n"]}