0c29ca6a086ef88a9eca87d6a30b3323.json
6.34 KB
{"ast":null,"code":"/**\n * Get index with specific start index one by one. e.g.\n * min: 3, max: 9, start: 6\n *\n * Return index is:\n * [0]: 6\n * [1]: 7\n * [2]: 5\n * [3]: 8\n * [4]: 4\n * [5]: 9\n * [6]: 3\n */\nexport function getIndexByStartLoc(min, max, start, index) {\n var beforeCount = start - min;\n var afterCount = max - start;\n var balanceCount = Math.min(beforeCount, afterCount) * 2; // Balance\n\n if (index <= balanceCount) {\n var stepIndex = Math.floor(index / 2);\n\n if (index % 2) {\n return start + stepIndex + 1;\n }\n\n return start - stepIndex;\n } // One is out of range\n\n\n if (beforeCount > afterCount) {\n return start - (index - afterCount);\n }\n\n return start + (index - beforeCount);\n}\n/**\n * We assume that 2 list has only 1 item diff and others keeping the order.\n * So we can use dichotomy algorithm to find changed one.\n */\n\nexport function findListDiffIndex(originList, targetList, getKey) {\n var originLen = originList.length;\n var targetLen = targetList.length;\n var shortList;\n var longList;\n\n if (originLen === 0 && targetLen === 0) {\n return null;\n }\n\n if (originLen < targetLen) {\n shortList = originList;\n longList = targetList;\n } else {\n shortList = targetList;\n longList = originList;\n }\n\n var notExistKey = {\n __EMPTY_ITEM__: true\n };\n\n function getItemKey(item) {\n if (item !== undefined) {\n return getKey(item);\n }\n\n return notExistKey;\n } // Loop to find diff one\n\n\n var diffIndex = null;\n var multiple = Math.abs(originLen - targetLen) !== 1;\n\n for (var i = 0; i < longList.length; i += 1) {\n var shortKey = getItemKey(shortList[i]);\n var longKey = getItemKey(longList[i]);\n\n if (shortKey !== longKey) {\n diffIndex = i;\n multiple = multiple || shortKey !== getItemKey(longList[i + 1]);\n break;\n }\n }\n\n return diffIndex === null ? null : {\n index: diffIndex,\n multiple: multiple\n };\n}","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/node_modules/rc-virtual-list/es/utils/algorithmUtil.js"],"names":["getIndexByStartLoc","min","max","start","index","beforeCount","afterCount","balanceCount","Math","stepIndex","floor","findListDiffIndex","originList","targetList","getKey","originLen","length","targetLen","shortList","longList","notExistKey","__EMPTY_ITEM__","getItemKey","item","undefined","diffIndex","multiple","abs","i","shortKey","longKey"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,kBAAT,CAA4BC,GAA5B,EAAiCC,GAAjC,EAAsCC,KAAtC,EAA6CC,KAA7C,EAAoD;AACzD,MAAIC,WAAW,GAAGF,KAAK,GAAGF,GAA1B;AACA,MAAIK,UAAU,GAAGJ,GAAG,GAAGC,KAAvB;AACA,MAAII,YAAY,GAAGC,IAAI,CAACP,GAAL,CAASI,WAAT,EAAsBC,UAAtB,IAAoC,CAAvD,CAHyD,CAGC;;AAE1D,MAAIF,KAAK,IAAIG,YAAb,EAA2B;AACzB,QAAIE,SAAS,GAAGD,IAAI,CAACE,KAAL,CAAWN,KAAK,GAAG,CAAnB,CAAhB;;AAEA,QAAIA,KAAK,GAAG,CAAZ,EAAe;AACb,aAAOD,KAAK,GAAGM,SAAR,GAAoB,CAA3B;AACD;;AAED,WAAON,KAAK,GAAGM,SAAf;AACD,GAbwD,CAavD;;;AAGF,MAAIJ,WAAW,GAAGC,UAAlB,EAA8B;AAC5B,WAAOH,KAAK,IAAIC,KAAK,GAAGE,UAAZ,CAAZ;AACD;;AAED,SAAOH,KAAK,IAAIC,KAAK,GAAGC,WAAZ,CAAZ;AACD;AACD;AACA;AACA;AACA;;AAEA,OAAO,SAASM,iBAAT,CAA2BC,UAA3B,EAAuCC,UAAvC,EAAmDC,MAAnD,EAA2D;AAChE,MAAIC,SAAS,GAAGH,UAAU,CAACI,MAA3B;AACA,MAAIC,SAAS,GAAGJ,UAAU,CAACG,MAA3B;AACA,MAAIE,SAAJ;AACA,MAAIC,QAAJ;;AAEA,MAAIJ,SAAS,KAAK,CAAd,IAAmBE,SAAS,KAAK,CAArC,EAAwC;AACtC,WAAO,IAAP;AACD;;AAED,MAA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7\n * [2]: 5\n * [3]: 8\n * [4]: 4\n * [5]: 9\n * [6]: 3\n */\nexport function getIndexByStartLoc(min, max, start, index) {\n var beforeCount = start - min;\n var afterCount = max - start;\n var balanceCount = Math.min(beforeCount, afterCount) * 2; // Balance\n\n if (index <= balanceCount) {\n var stepIndex = Math.floor(index / 2);\n\n if (index % 2) {\n return start + stepIndex + 1;\n }\n\n return start - stepIndex;\n } // One is out of range\n\n\n if (beforeCount > afterCount) {\n return start - (index - afterCount);\n }\n\n return start + (index - beforeCount);\n}\n/**\n * We assume that 2 list has only 1 item diff and others keeping the order.\n * So we can use dichotomy algorithm to find changed one.\n */\n\nexport function findListDiffIndex(originList, targetList, getKey) {\n var originLen = originList.length;\n var targetLen = targetList.length;\n var shortList;\n var longList;\n\n if (originLen === 0 && targetLen === 0) {\n return null;\n }\n\n if (originLen < targetLen) {\n shortList = originList;\n longList = targetList;\n } else {\n shortList = targetList;\n longList = originList;\n }\n\n var notExistKey = {\n __EMPTY_ITEM__: true\n };\n\n function getItemKey(item) {\n if (item !== undefined) {\n return getKey(item);\n }\n\n return notExistKey;\n } // Loop to find diff one\n\n\n var diffIndex = null;\n var multiple = Math.abs(originLen - targetLen) !== 1;\n\n for (var i = 0; i < longList.length; i += 1) {\n var shortKey = getItemKey(shortList[i]);\n var longKey = getItemKey(longList[i]);\n\n if (shortKey !== longKey) {\n diffIndex = i;\n multiple = multiple || shortKey !== getItemKey(longList[i + 1]);\n break;\n }\n }\n\n return diffIndex === null ? null : {\n index: diffIndex,\n multiple: multiple\n };\n}"]},"metadata":{},"sourceType":"module"}