You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
5.8 KiB
1 line
5.8 KiB
4 years ago
|
!function(a,b){if("function"==typeof define&&define.amd)define("timsort",["exports"],b);else if("undefined"!=typeof exports)b(exports);else{var c={exports:{}};b(c.exports),a.timsort=c.exports}}(this,function(a){"use strict";function b(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function c(a){return a<1e5?a<100?a<10?0:1:a<1e4?a<1e3?2:3:4:a<1e7?a<1e6?5:6:a<1e9?a<1e8?7:8:9}function d(a,b){if(a===b)return 0;if(~~a===a&&~~b===b){if(0===a||0===b)return a<b?-1:1;if(a<0||b<0){if(b>=0)return-1;if(a>=0)return 1;a=-a,b=-b}var d=c(a),e=c(b),f=0;return d<e?(a*=o[e-d-1],b/=10,f=-1):d>e&&(b*=o[d-e-1],a/=10,f=1),a===b?f:a<b?-1:1}var g=String(a),h=String(b);return g===h?0:g<h?-1:1}function e(a){for(var b=0;a>=l;)b|=1&a,a>>=1;return a+b}function f(a,b,c,d){var e=b+1;if(e===c)return 1;if(d(a[e++],a[b])<0){for(;e<c&&d(a[e],a[e-1])<0;)e++;g(a,b,e)}else for(;e<c&&d(a[e],a[e-1])>=0;)e++;return e-b}function g(a,b,c){for(c--;b<c;){var d=a[b];a[b++]=a[c],a[c--]=d}}function h(a,b,c,d,e){for(d===b&&d++;d<c;d++){for(var f=a[d],g=b,h=d;g<h;){var i=g+h>>>1;e(f,a[i])<0?h=i:g=i+1}var j=d-g;switch(j){case 3:a[g+3]=a[g+2];case 2:a[g+2]=a[g+1];case 1:a[g+1]=a[g];break;default:for(;j>0;)a[g+j]=a[g+j-1],j--}a[g]=f}}function i(a,b,c,d,e,f){var g=0,h=0,i=1;if(f(a,b[c+e])>0){for(h=d-e;i<h&&f(a,b[c+e+i])>0;)g=i,i=(i<<1)+1,i<=0&&(i=h);i>h&&(i=h),g+=e,i+=e}else{for(h=e+1;i<h&&f(a,b[c+e-i])<=0;)g=i,i=(i<<1)+1,i<=0&&(i=h);i>h&&(i=h);var j=g;g=e-i,i=e-j}for(g++;g<i;){var k=g+(i-g>>>1);f(a,b[c+k])>0?g=k+1:i=k}return i}function j(a,b,c,d,e,f){var g=0,h=0,i=1;if(f(a,b[c+e])<0){for(h=e+1;i<h&&f(a,b[c+e-i])<0;)g=i,i=(i<<1)+1,i<=0&&(i=h);i>h&&(i=h);var j=g;g=e-i,i=e-j}else{for(h=d-e;i<h&&f(a,b[c+e+i])>=0;)g=i,i=(i<<1)+1,i<=0&&(i=h);i>h&&(i=h),g+=e,i+=e}for(g++;g<i;){var k=g+(i-g>>>1);f(a,b[c+k])<0?i=k:g=k+1}return i}function k(a,b,c,g){if(!Array.isArray(a))throw new TypeError("Can only sort arrays");b?"function"!=typeof b&&(g=c,c=b,b=d):b=d,c||(c=0),g||(g=a.length);var i=g-c;if(!(i<2)){var j=0;if(i<l)return j=f(a,c,g,b),void h(a,c,g,c+j,b);var k=new p(a,b),m=e(i);do{if(j=f(a,c,g,b),j<m){var n=i;n>m&&(n=m),h(a,c,c+n,c+j,b),j=n}k.pushRun(c,j),k.mergeRuns(),i-=j,c+=j}while(0!==i);k.forceMergeRuns()}}a.__esModule=!0,a.sort=k;var l=32,m=7,n=256,o=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9],p=function(){function a(c,d){b(this,a),this.array=null,this.compare=null,this.minGallop=m,this.length=0,this.tmpStorageLength=n,this.stackLength=0,this.runStart=null,this.runLength=null,this.stackSize=0,this.array=c,this.compare=d,this.length=c.length,this.length<2*n&&(this.tmpStorageLength=this.length>>>1),this.tmp=new Array(this.tmpStorageLength),this.stackLength=this.length<120?5:this.length<1542?10:this.length<119151?19:40,this.runStart=new Array(this.stackLength),this.runLength=new Array(this.stackLength)}return a.prototype.pushRun=function(a,b){this.runStart[this.stackSize]=a,this.runLength[this.stackSize]=b,this.stackSize+=1},a.prototype.mergeRuns=function(){for(;this.stackSize>1;){var a=this.stackSize-2;if(a>=1&&this.runLength[a-1]<=this.runLength[a]+this.runLength[a+1]||a>=2&&this.runLength[a-2]<=this.runLength[a]+this.runLength[a-1])this.runLength[a-1]<this.runLength[a+1]&&a--;else if(this.runLength[a]>this.runLength[a+1])break;this.mergeAt(a)}},a.prototype.forceMergeRuns=function(){for(;this.stackSize>1;){var a=this.stackSize-2;a>0&&this.runLength[a-1]<this.runLength[a+1]&&a--,this.mergeAt(a)}},a.prototype.mergeAt=function(a){var b=this.compare,c=this.array,d=this.runStart[a],e=this.runLength[a],f=this.runStart[a+1],g=this.runLength[a+1];this.runLength[a]=e+g,a===this.stackSize-3&&(this.runStart[a+1]=this.runStart[a+2],this.runLength[a+1]=this.runLength[a+2]),this.stackSize--;var h=j(c[f],c,d,e,0,b);d+=h,e-=h,0!==e&&(g=i(c[d+e-1],c,f,g,g-1,b),0!==g&&(e<=g?this.mergeLow(d,e,f,g):this.mergeHigh(d,e,f,g)))},a.prototype.mergeLow=function(a,b,c,d){var e=this.compare,f=this.array,g=this.tmp,h=0;for(h=0;h<b;h++)g[h]=f[a+h];var k=0,l=c,n=a;if(f[n++]=f[l++],0!==--d){if(1===b){for(h=0;h<d;h++)f[n+h]=f[l+h];return void(f[n+d]=g[k])}for(var o=this.minGallop;;
|