-
Notifications
You must be signed in to change notification settings - Fork 7
/
radixsort.min.js
3 lines (3 loc) · 2.82 KB
/
radixsort.min.js
1
2
3
// Based on http://stereopsis.com/radix.html
// Requires typed arrays.
(function(e){function s(){function e(e,r){var s,w,E,S,x=!1;e instanceof Float32Array?(s=l,w=c,E=h,S=y,x=!0):e instanceof Float64Array?(s=p,w=d,E=v,S=b,x=!0):e instanceof Uint32Array||e instanceof Uint16Array||e instanceof Uint8Array?(s=o,w=E=f,S=g):(s=o,w=u,E=a,S=m);var T=x?new Int32Array(e.buffer,e.byteOffset,e.byteLength>>2):e,N=Math.ceil(e.BYTES_PER_ELEMENT*8/t),C=n*(N-1),k=1<<(e.BYTES_PER_ELEMENT*8-1)%t,L=(k<<1)-1,A;r=r?x?new Int32Array(r.buffer,r.byteOffset,r.byteLength>>2):r:new T.constructor(T.length);for(var O=0,M=n*N;O<M;O++)i[O]=0;S(T,C,L);for(var _=0;_<=C;_+=n)for(var D=_,P=0;D<_+n;D++){var H=i[D]+P;i[D]=P-1,P=H}var B=0;N--;if(N){s(T,r),A=r,r=T,T=A;while(++B<N)w(T,r,B),A=r,r=T,T=A}return E(T,r,B,k),new e.constructor(r.buffer,r.byteOffset,e.length)}return e.radix=function(o){return arguments.length?(n=1<<(t=+o),r=n-1,i=s._histograms=new Int32Array(n*Math.ceil(64/t)),e):t},e.radix(11)}function o(e,t){for(var n=0,s=e.length;n<s;n++){var o=e[n];t[++i[o&r]]=o}}function u(e,s,o){for(var u=0,a=e.length,f=o*n,l=o*t;u<a;u++){var c=e[u];s[++i[f+(c>>>l&r)]]=c}}function a(e,r,s,o){var u=(o<<1)-1;for(var a=0,f=e.length,l=s*n,c=s*t;a<f;a++){var h=e[a];r[++i[l+(h>>>c&u^o)]]=h}}function f(e,s,o){for(var u=0,a=e.length,f=o*n,l=o*t;u<a;u++){var c=e[u],h=c>>>l&r;s[++i[f+h]]=c}}function l(e,t){for(var n=0,s=e.length;n<s;n++){var o=e[n];o^=o>>31|2147483648,t[++i[o&r]]=o}}function c(e,s,o){for(var u=0,a=e.length,f=o*n,l=o*t;u<a;u++){var c=e[u];s[++i[f+(c>>>l&r)]]=c}}function h(e,r,s,o){var u=(o<<1)-1;for(var a=0,f=e.length,l=s*n,c=s*t;a<f;a++){var h=e[a],p=h>>>c&u;r[++i[l+p]]=h^(~h>>31|2147483648)}}function p(e,t){for(var n=0,s=e.length;n<s;n++){var o=e[n],u=e[++n],a=u>>31;u^=a|2147483648,o^=a,a=++i[o&r]<<1,t[a++]=o,t[a]=u}}function d(e,s,o){var u=o*t,a=r,f=0,l=32-u,c=u<32&&u>32-t?(a=-1>>>u&r,f=0,-1<<l&r):u>=32?(u-=32,l+=32,a=0,f=r,0):0;for(var h=0,p=e.length,d=o*n,u=o*t;h<p;h++){var v=e[h],m=e[++h],g=++i[d+(v>>>u&a|m>>>u&f|m<<l&c)]<<1;s[g++]=v,s[g]=m}}function v(e,r,s,o){var u=(o<<1)-1;for(var a=0,f=e.length,l=s*n,c=s*t-32;a<f;a++){var h=e[a],p=e[++a],d=p>>>c&u,v=~p>>31;d=++i[l+d]<<1,r[d++]=h^v,r[d]=p^(v|2147483648)}}function m(e,s,o){var u=o+1>>>1;for(var a=0,f=e.length;a<f;a++){var l=e[a];for(var c=0,h=0;c<s;c+=n,h+=t)i[c+(l>>>h&r)]++;i[c+(l>>>h&o^u)]++}}function g(e,s){for(var o=0,u=e.length;o<u;o++){var a=e[o];for(var f=0,l=0;f<=s;f+=n,l+=t)i[f+(a>>>l&r)]++}}function y(e,s,o){for(var u=0,a=e.length;u<a;u++){var f=e[u];f^=f>>31|2147483648;for(var l=0,c=0;l<s;l+=n,c+=t)i[l+(f>>>c&r)]++;i[l+(f>>>c&o)]++}}function b(e,s,o){for(var u=0,a=e.length;u<a;u++){var f=e[u],l=e[++u],c=l>>31;l^=c|2147483648,f^=c;for(var h=0,p=0;p<=32-t;h+=n,p+=t)i[h+(f>>>p&r)]++;i[h+((l<<32-p|f>>>p)&r)]++;for(p+=t-32,h+=n;h<s;h+=n,p+=t)i[h+(l>>>p&r)]++;i[h+(l>>>p&o)]++}}e.radixsort=s;var t,n,r,i})(this);