feat: refactoring project
This commit is contained in:
17
node_modules/webpack/lib/util/binarySearchBounds.js
generated
vendored
17
node_modules/webpack/lib/util/binarySearchBounds.js
generated
vendored
@@ -22,7 +22,6 @@
|
||||
* ```js
|
||||
* function P(a,l,h,y,c){var i=l-1;while(l<=h){var m=(l+h)>>>1,x=a[m];if(c(x,y)<=0){i=m;l=m+1}else{h=m-1}}return i};
|
||||
* ```
|
||||
*
|
||||
* @param {string} funcName The name of the function to be compiled.
|
||||
* @param {string} predicate The predicate / comparison operator to be used in the binary search.
|
||||
* @param {boolean} reversed Whether the search should be reversed.
|
||||
@@ -43,7 +42,7 @@ const compileSearch = (funcName, predicate, reversed, extraArgs, earlyOut) => {
|
||||
];
|
||||
|
||||
if (earlyOut) {
|
||||
if (predicate.indexOf("c") < 0) {
|
||||
if (!predicate.includes("c")) {
|
||||
code.push(";if(x===y){return m}else if(x<=y){");
|
||||
} else {
|
||||
code.push(";var p=c(x,y);if(p===0){return m}else if(p<=0){");
|
||||
@@ -70,7 +69,6 @@ const compileSearch = (funcName, predicate, reversed, extraArgs, earlyOut) => {
|
||||
* A(): Performs a binary search on an array using the comparison operator specified.
|
||||
* P(): Performs a binary search on an array using a _custom comparison function_
|
||||
* `c(x,y)` **and** comparison operator specified by `predicate`.
|
||||
*
|
||||
* @param {BinarySearchPredicate} predicate The predicate / comparison operator to be used in the binary search.
|
||||
* @param {boolean} reversed Whether the search should be reversed.
|
||||
* @param {SearchPredicateSuffix} suffix The suffix to be used in the function name.
|
||||
@@ -78,17 +76,11 @@ const compileSearch = (funcName, predicate, reversed, extraArgs, earlyOut) => {
|
||||
* @returns {Function} The compiled binary search function.
|
||||
*/
|
||||
const compileBoundsSearch = (predicate, reversed, suffix, earlyOut) => {
|
||||
const arg1 = compileSearch(
|
||||
"A",
|
||||
"x" + predicate + "y",
|
||||
reversed,
|
||||
["y"],
|
||||
earlyOut
|
||||
);
|
||||
const arg1 = compileSearch("A", `x${predicate}y`, reversed, ["y"], earlyOut);
|
||||
|
||||
const arg2 = compileSearch(
|
||||
"P",
|
||||
"c(x,y)" + predicate + "0",
|
||||
`c(x,y)${predicate}0`,
|
||||
reversed,
|
||||
["y", "c"],
|
||||
earlyOut
|
||||
@@ -97,6 +89,7 @@ const compileBoundsSearch = (predicate, reversed, suffix, earlyOut) => {
|
||||
const fnHeader = "function dispatchBinarySearch";
|
||||
|
||||
const fnBody =
|
||||
// eslint-disable-next-line no-multi-str
|
||||
"(a,y,c,l,h){\
|
||||
if(typeof(c)==='function'){\
|
||||
return P(a,(l===void 0)?0:l|0,(h===void 0)?a.length-1:h|0,y,c)\
|
||||
@@ -107,13 +100,13 @@ return dispatchBinarySearch";
|
||||
|
||||
const fnArgList = [arg1, arg2, fnHeader, suffix, fnBody, suffix];
|
||||
const fnSource = fnArgList.join("");
|
||||
// eslint-disable-next-line no-new-func
|
||||
const result = new Function(fnSource);
|
||||
return result();
|
||||
};
|
||||
|
||||
/**
|
||||
* These functions are used to perform binary searches on arrays.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
* const { gt, le} = require("./binarySearchBounds");
|
||||
|
||||
Reference in New Issue
Block a user