{"version":3,"sources":["https://lively-kernel.org/lively4/swd21-event-sourcing/src/client/reactive/active-expression-rewriting/composite-key.js"],"names":["CompositeKey","constructor","_compositeKeyStore","Map","_compositeKeyStoreReverse","_newMap","_getByPrimaryKey","obj1","getOrCreate","_get","obj2","secondKeyMap","has","compKey","set","get","for","keysFor","remove","delete","size","clear"],"mappings":";;;;;;;;AAAe,YAAMA,YAAN,CAAmB;;AAEhCC,sBAAc;AACZ,eAAKC,kBAAL,GAA0B,IAAIC,GAAJ,EAA1B;AACA,eAAKC,yBAAL,GAAiC,IAAID,GAAJ,EAAjC;AACD;;AAEDE,kBAAU;AAAE,iBAAO,IAAIF,GAAJ,EAAP;AAAmB;;AAE/BG,yBAAiBC,IAAjB,EAAuB;AACrB,iBAAO,KAAKL,kBAAL,CAAwBM,WAAxB,CAAoCD,IAApC,EAA0C,KAAKF,OAA/C,CAAP;AACD;AACDI,aAAKF,IAAL,EAAWG,IAAX,EAAiB;AACf,gBAAMC,eAAe,KAAKL,gBAAL,CAAsBC,IAAtB,CAArB;AACA,cAAG,CAACI,aAAaC,GAAb,CAAiBF,IAAjB,CAAJ,EAA4B;AAC1B,kBAAMG,UAAU,EAAhB;AACAF,yBAAaG,GAAb,CAAiBJ,IAAjB,EAAuBG,OAAvB;AACA,iBAAKT,yBAAL,CAA+BU,GAA/B,CAAmCD,OAAnC,EAA4C,CAACN,IAAD,EAAOG,IAAP,CAA5C;AACD;AACD,iBAAOC,aAAaI,GAAb,CAAiBL,IAAjB,CAAP;AACD;;AAEDM,YAAIT,IAAJ,EAAUG,IAAV,EAAgB;AACd,iBAAO,KAAKD,IAAL,CAAUF,IAAV,EAAgBG,IAAhB,CAAP;AACD;;AAED;;;AAGAO,gBAAQJ,OAAR,EAAiB;AACf,iBAAO,KAAKT,yBAAL,CAA+BW,GAA/B,CAAmCF,OAAnC,KAA+C,EAAtD;AACD;;AAEDK,eAAOL,OAAP,EAAgB;AACd,gBAAM,CAACN,IAAD,EAAOG,IAAP,IAAe,KAAKN,yBAAL,CAA+BW,GAA/B,CAAmCF,OAAnC,CAArB;;AAEA,gBAAMF,eAAe,KAAKL,gBAAL,CAAsBC,IAAtB,CAArB;AACAI,uBAAaQ,MAAb,CAAoBT,IAApB;AACA,cAAGC,aAAaS,IAAb,KAAsB,CAAzB,EAA4B;AAC1B,iBAAKlB,kBAAL,CAAwBiB,MAAxB,CAA+BZ,IAA/B;AACD;AACD,eAAKH,yBAAL,CAA+Be,MAA/B,CAAsCN,OAAtC;AACD;;AAEDQ,gBAAQ;AACN,eAAKnB,kBAAL,CAAwBmB,KAAxB;AACA,eAAKjB,yBAAL,CAA+BiB,KAA/B;AACD;AA/C+B;;yBAAbrB,Y;;;;;;;;6BAAAA,6C","file":"composite-key.js","sourcesContent":["export default class CompositeKey {\n\n  constructor() {\n    this._compositeKeyStore = new Map();\n    this._compositeKeyStoreReverse = new Map();\n  }\n\n  _newMap() { return new Map(); }\n  \n  _getByPrimaryKey(obj1) {\n    return this._compositeKeyStore.getOrCreate(obj1, this._newMap);\n  }\n  _get(obj1, obj2) {\n    const secondKeyMap = this._getByPrimaryKey(obj1);\n    if(!secondKeyMap.has(obj2)) {\n      const compKey = {};\n      secondKeyMap.set(obj2, compKey);\n      this._compositeKeyStoreReverse.set(compKey, [obj1, obj2]);\n    }\n    return secondKeyMap.get(obj2);\n  }\n  \n  for(obj1, obj2) {\n    return this._get(obj1, obj2);\n  }\n  \n  /**\n   * Reverse operation of @link(for)\n   */\n  keysFor(compKey) {\n    return this._compositeKeyStoreReverse.get(compKey) || [];\n  }\n  \n  remove(compKey) {\n    const [obj1, obj2] = this._compositeKeyStoreReverse.get(compKey);\n    \n    const secondKeyMap = this._getByPrimaryKey(obj1);\n    secondKeyMap.delete(obj2);\n    if(secondKeyMap.size === 0) {\n      this._compositeKeyStore.delete(obj1);\n    }\n    this._compositeKeyStoreReverse.delete(compKey);\n  }\n  \n  clear() {\n    this._compositeKeyStore.clear();\n    this._compositeKeyStoreReverse.clear();\n  }\n}\n"]}