1 line
6.2 KiB
JSON
1 line
6.2 KiB
JSON
|
{"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;\n\n // Balance\n if (index <= balanceCount) {\n var stepIndex = Math.floor(index / 2);\n if (index % 2) {\n return start + stepIndex + 1;\n }\n return start - stepIndex;\n }\n\n // One is out of range\n if (beforeCount > afterCount) {\n return start - (index - afterCount);\n }\n return start + (index - beforeCount);\n}\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 */\nexport function findListDiffIndex(originList, targetList, getKey) {\n var originLen = originList.length;\n var targetLen = targetList.length;\n var shortList;\n var longList;\n if (originLen === 0 && targetLen === 0) {\n return null;\n }\n if (originLen < targetLen) {\n shortList = originList;\n longList = targetList;\n } else {\n shortList = targetList;\n longList = originList;\n }\n var notExistKey = {\n __EMPTY_ITEM__: true\n };\n function getItemKey(item) {\n if (item !== undefined) {\n return getKey(item);\n }\n return notExistKey;\n }\n\n // Loop to find diff one\n var diffIndex = null;\n var multiple = Math.abs(originLen - targetLen) !== 1;\n for (var i = 0; i < longList.length; i += 1) {\n var shortKey = getItemKey(shortList[i]);\n var longKey = getItemKey(longList[i]);\n if (shortKey !== longKey) {\n diffIndex = i;\n multiple = multiple || shortKey !== getItemKey(longList[i + 1]);\n break;\n }\n }\n return diffIndex === null ? null : {\n index: diffIndex,\n multiple: multiple\n };\n}","map":{"version":3,"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"],"sources":["C:/Users/Аришина)/source/repos/PromoCursed/node_modules/rc-virtual-list/es/utils/algorithmUtil.js"],"sourcesContent":["/**\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;\n\n // Balance\n if (index <= balanceCount) {\n var stepIndex = Math.floor(index / 2);\n if (index % 2) {\n return start + stepIndex + 1;\n }\n return start - stepIndex;\n }\n\n // One is out of range\n if (beforeCount > afterCount) {\n return start - (index - afterCount);\n }\n return start + (index - beforeCount);\n}\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 */\nexport function findListDiffIndex(originList, targetList, getKey) {\n var originLen = originList.length;\n var targetLen = targetList.length;\n var shortList;\n var longList;\n if (originLen === 0 && targetLen === 0) {\n return null;\n }\n if (originLen < targetLen) {\n shortList = originList;\n longList = targetList;\n } else {\n shortList = targetList;\n longList = originList;\n }\n var notExistKey = {\n __EMPTY_ITEM__: true\n };\n function getItemKey(item) {\n if (item !== undefined) {\n return getKey(item);\n }\n return notExistKey;\n }\n\n // Loop to find diff one\n var diffIndex = null;\n var multiple = Math.abs(originLen - targetLen) !==
|