-
Notifications
You must be signed in to change notification settings - Fork 1
/
2darray.min.js
6 lines (6 loc) · 2.15 KB
/
2darray.min.js
1
2
3
4
5
6
/* 2darray.js by TheGreatRambler copyright 2018 */
(function(b,c){"function"===typeof define&&define.amd?define([],c):"object"===typeof module&&module.exports?module.exports=c():b.tdarrayindex=c()})("undefined"!==typeof self?self:this,function(){return{encode:function(b,c,e,f){if("undefined"===typeof f||!1===f){var d=b;var a=c}else!0===f?(d=0<=b?2*b:-2*b-1,a=0<=c?2*c:-2*c-1):console.warn(f+" is not valid; this option must be a bool");if(e&&"szudzik"!==e){if("interleave"===e){b=d.toString();a=a.toString();b.length>a.length?(c=Array(b.length-a.length+
1).join("0"),a=c+a):a.length>b.length&&(c=Array(a.length-b.length+1).join("0"),b=c+b);c=b.length;e="";for(f=0;f<c;f++)e+=b[f]+a[f];return Number(e)}if("triangle"===e)return a=(Math.pow(d+a-1,2)+d+a-1)/2+a;if("primefactor"===e)return a=Math.pow(2,a)*Math.pow(3,d);if("cantorpair"===e)return(d+a)*(d+a+1)/2+a;if("bitwise"===e)return d<<16&4294901760|a&65535;if("hopullman"===e)return(d+a-2)*(d+a-1)/2+d;if("rosenstrong"===e)return a=Math.pow(Math.max(d,a),2)+Math.max(d,a)+d-a;console.warn(e+" is not a valid method")}else return d>=
a?d*d+d+a:a*a+d},decode:function(b,c,e,f){var d;"undefined"===typeof f||!0===f?d=!0:!1===f?d=!1:console.warn(f+"incorrect option; must be bool");if(c&&"szudzik"!==c)if("interleaving"===c){b=b.toString();0!==b.length%2&&(b="0"+b);for(c=0;c<b.length-1;c+=2)g+=b.charAt(c),h+=b.charAt(c+1);var a=[Number(g),Number(h)]}else if("triangle"===c)d&&console.warn("decoding method for triangular number does not exist");else if("primefactor"===c)d&&console.warn("decoding method for prime factorization does not exist");
else if("cantorpair"===c){var g=Math.floor((Math.sqrt(1+8*b)-1)/2);a=[g*(g+3)/2-b,b-g*(g+1)/2]}else"bitwise"===c?a=[b>>16&65535,b&65535]:"hopullman"===c?d&&console.warn("decoding method for Hopkins Ullman pairing algorithm does not exist"):"rosenstrong"===c?d&&console.warn("decoding method for Rosenburg Strong pairing algorithm does not exist"):console.warn(c+" is not a valid method");else{g=Math.floor(Math.sqrt(b));var h=g*g;a=b-h>=g?[g,b-h-g]:[b-h,g]}if(e&&!1!==e){if(!0===e)return[0===a[1]%2?a[1]/
2:(a[1]+1)/2*-1,y];console.warn(e+" is not valid; this option must be a bool")}else return a}}});