diff --git a/.codacy.yml b/.codacy.yml new file mode 100644 index 0000000..0672c33 --- /dev/null +++ b/.codacy.yml @@ -0,0 +1,7 @@ +languages: + JavaScript: true +exclude_paths: +- "js/dist/*.js" +- "js/dist/**/*.js" +- "test/*.js" +- "test/**/*.js" diff --git a/README.md b/README.md index fbb74db..978ff39 100644 --- a/README.md +++ b/README.md @@ -1,76 +1,144 @@ -[js-algorithms](http://aureooms.github.io/js-algorithms) +:rocket: [Algorithms](https://github.com/make-github-pseudonymous-again/js-algorithms#readme) +[](https://raw.githubusercontent.com/make-github-pseudonymous-again/js-algorithms/main/LICENSE) +[](https://github.com/make-github-pseudonymous-again/js-algorithms/issues) == -Algorithms code bricks in JavaScript. This is a child project of -[js-library](https://github.com/aureooms/js-library) and the twin project -of [js-data-structures](https://github.com/aureooms/js-data-structures). +
-[](https://raw.githubusercontent.com/aureooms/js-algorithms/master/LICENSE) -[](https://www.npmjs.org/package/aureooms-js-algorithms) -[](http://bower.io/search/?q=aureooms-js-algorithms) -[](https://travis-ci.org/aureooms/js-algorithms) -[](https://coveralls.io/r/aureooms/js-algorithms) -[](https://david-dm.org/aureooms/js-algorithms#info=dependencies) -[](https://david-dm.org/aureooms/js-algorithms#info=devDependencies) -[](https://codeclimate.com/github/aureooms/js-algorithms) -[](https://www.npmjs.org/package/aureooms-js-algorithms) -[](https://github.com/aureooms/js-algorithms/issues) -[](http://inch-ci.org/github/aureooms/js-algorithms) +Playground for algorithms in JavaScript. +This is a child project of [js-library](https://github.com/make-github-pseudonymous-again/js-library) +and +the twin project of [js-data-structures](https://github.com/make-github-pseudonymous-again/js-data-structures). -## Description + +## :newspaper: Description This project is just a playground for any algorithm that doesn't fit in any -of those project, - - - [aureooms/js-cg](https://github.com/aureooms/js-cg) : computational geometry code bricks for JavaScript - - [aureooms/js-complex](https://github.com/aureooms/js-complex) : complex numbers code bricks for JavaScript - - [aureooms/js-equation](https://github.com/aureooms/js-equation) : equations system code bricks for JavaScript - - [aureooms/js-fft](https://github.com/aureooms/js-fft) : fast Fourier transform code bricks for JavaScript - - [aureooms/js-fibonacci](https://github.com/aureooms/js-fibonacci) : Fibonacci numbers code bricks for JavaScript - - [aureooms/js-gn](https://github.com/aureooms/js-gn) : graphs and networks code bricks for JavaScript - - [aureooms/js-hash](https://github.com/aureooms/js-hash) : hashing algorithms code bricks for JavaScript - - [aureooms/js-ho](https://github.com/aureooms/js-ho) : heuristic optimization code bricks for JavaScript - - [aureooms/js-hypermatrix](https://github.com/aureooms/js-hypermatrix) : hypermatrices code bricks for JavaScript - - [aureooms/js-integer](https://github.com/aureooms/js-integer) : multi-precision arithmetic code bricks for JavaScript - - [aureooms/js-matrix](https://github.com/aureooms/js-matrix) : matrices code bricks for JavaScript - - [aureooms/js-nlp](https://github.com/aureooms/js-nlp) : natural language processing code bricks for JavaScript - - [aureooms/js-oro](https://github.com/aureooms/js-oro) : operations research and optimization algorithm templates for JavaScript - - [aureooms/js-permutation](https://github.com/aureooms/js-permutation) : permutations code bricks for JavaScript - - [aureooms/js-pfsp-wt](https://github.com/aureooms/js-pfsp-wt) : permutation flow-shop problem (PFSP) with weighted tardiness objective (PFSP-WT) code bricks for JavaScript - - [aureooms/js-polynomial](https://github.com/aureooms/js-polynomial) : sparse and dense polynomials code bricks for JavaScript - - [aureooms/js-prime](https://github.com/aureooms/js-prime) : prime numbers code bricks for JavaScript - - [aureooms/js-random](https://github.com/aureooms/js-random) : randomness code bricks for JavaScript - - [aureooms/js-rational](https://github.com/aureooms/js-rational) : rational numbers code bricks for JavaScript - - [aureooms/js-search](https://github.com/aureooms/js-search) : item retrieval code bricks for JavaScript - - [aureooms/js-splitting](https://github.com/aureooms/js-splitting): splitting code bricks for JavaScript - - [aureooms/js-sort](https://github.com/aureooms/js-sort) : sorting code bricks for JavaScript - - [aureooms/js-in-situ-sort-spec](https://github.com/aureooms/js-in-situ-sort-spec): in place sorting code bricks for JavaScript - - [aureooms/js-heapsort](https://github.com/aureooms/js-heapsort): heapsort code bricks for JavaScript - - [aureooms/js-quicksort](https://github.com/aureooms/js-quicksort): quicksort code bricks for JavaScript - - [aureooms/js-mergesort](https://github.com/aureooms/js-mergesort): mergesort code bricks for JavaScript - - [aureooms/js-merging](https://github.com/aureooms/js-merging): merging code bricks for JavaScript - - [aureooms/js-partition](https://github.com/aureooms/js-partition): partition code bricks for JavaScript - - [aureooms/js-selection](https://github.com/aureooms/js-selection): selection code bricks for JavaScript - - [aureooms/js-string](https://github.com/aureooms/js-string) : character sequence code bricks for JavaScript +of those projects, + +### :flashlight: Searching + - [@aureooms/js-search](https://github.com/make-github-pseudonymous-again/js-search): + Searching algorithms for JavaScript + +### :waning_gibbous_moon: Merging + + - [aureooms/js-merging](https://github.com/make-github-pseudonymous-again/js-merging): merging for JavaScript + +### :cake: Partitioning + - [@aureooms/js-partition](https://github.com/make-github-pseudonymous-again/js-partition): + Partitioning algorithms for JavaScript + - [@aureooms/js-splitting](https://github.com/make-github-pseudonymous-again/js-splitting): + Array splitting algorithms for JavaScript + +### :point_down: Selection + - [aureooms/js-selection](https://github.com/make-github-pseudonymous-again/js-selection): selection for JavaScript + +### :signal_strength: Sorting + - [@aureooms/js-sort](https://github.com/make-github-pseudonymous-again/js-sort): + Sorting algorithms for JavaScript + +#### :balance_scale: Comparison sorting + + - :notebook_with_decorative_cover: [@comparison-sorting/specification](https://github.com/comparison-sorting/specification): Comparison sorting specification for JavaScript + - :leaves: [@comparison-sorting/heap-sort](https://github.com/comparison-sorting/heap-sort): Heapsort for JavaScript + - :rabbit2: [@comparison-sorting/quick-sort](https://github.com/comparison-sorting/quick-sort): Quicksort for JavaScript + - :rewind: [@comparison-sorting/insertion-sort](https://github.com/comparison-sorting/insertion-sort): Insertion sorting algorithms for JavaScript + - :person_fencing: [@comparison-sorting/merge-insertion-sort](https://github.com/comparison-sorting/merge-insertion-sort): Ford-Johnson algorithm for JavaScript + - :dragon: [@comparison-sorting/merge-sort](https://github.com/comparison-sorting/merge-sort): Mergesort for JavaScript + - :musical_score: [@comparison-sorting/odd-even-merge-sort](https://github.com/comparison-sorting/odd-even-merge-sort): Batcher's odd-even mergesort for JavaScript + +#### :zzz: Integer sorting + + - :oden: [@integer-sorting/radix-sort](https://github.com/integer-sorting/radix-sort): Radix sorting algorithms for JavaScript + - [aureooms/js-countingsort](https://github.com/make-github-pseudonymous-again/js-countingsort): countingsort for JavaScript + - [aureooms/js-bucketsort](https://github.com/make-github-pseudonymous-again/js-bucketsort): bucketsort for JavaScript + +### :symbols: Strings + Nothing yet. + +### :hocho: Hashing + Nothing yet. + +### :triangular_ruler: Geometry + - [@aureooms/js-cg](https://github.com/make-github-pseudonymous-again/js-cg) : computational geometry code bricks for JavaScript + +### :globe_with_meridians: Graphs + - [@aureooms/js-gn](https://github.com/make-github-pseudonymous-again/js-gn) : graphs and networks code bricks for JavaScript + - :oden: [@graph-algorithm/topological-sorting](https://github.com/graph-algorithm/topological-sorting): + Topological sorting algorithms for Javascript + - :haircut_woman: [@graph-algorithm/minimum-cut](https://github.com/graph-algorithm/minimum-cut): + Minimum cut algorithms for JavaScript + - :blossom: [@graph-algorithm/maximum-matching](https://github.com/graph-algorithm/maximum-matching): + Maximum matching algorithms for JavaScript + +### :1234: Numbers + + - :zzz: [@aureooms/js-integer](https://github.com/make-github-pseudonymous-again/js-integer) : + Integers for JavaScript (ℤ) + - :woman_farmer: [@aureooms/js-rational-field](https://github.com/make-github-pseudonymous-again/js-rational-field) : Rational field for JavaScript (ℚ) + +#### :symbols: Arithmetic + - :elephant: [@aureooms/js-integer-big-endian](https://github.com/make-github-pseudonymous-again/js-integer-big-endian): Arbitrary precision arithmetic for integers in big-endian order for JavaScript + - :pizza: [@aureooms/js-rational](https://github.com/make-github-pseudonymous-again/js-rational) : rational numbers code bricks for JavaScript + - :mermaid: [@aureooms/js-modular-arithmetic](https://github.com/make-github-pseudonymous-again/js-modular-arithmetic): Modular arithmetic for JavaScript. + - :globe_with_meridians: [@aureooms/js-complex](https://github.com/make-github-pseudonymous-again/js-complex) : complex numbers code bricks for JavaScript + - :wavy_dash: [@aureooms/js-polynomial](https://github.com/make-github-pseudonymous-again/js-polynomial) : sparse and dense polynomials code bricks for JavaScript + +#### :two: :three: :five: :seven: Number theory + - :butterfly: [@aureooms/js-fft](https://github.com/make-github-pseudonymous-again/js-fft) : Fast Fourier transform algorithms for JavaScript + - [@aureooms/js-prime](https://github.com/make-github-pseudonymous-again/js-prime) : Prime numbers for JavaScript + +#### :shell: Integer sequences + - [@aureooms/js-integer-sequences](https://github.com/make-github-pseudonymous-again/js-integer-sequences) : Integer sequences for JavaScript + - [@aureooms/js-fibonacci](https://github.com/make-github-pseudonymous-again/js-fibonacci) : Fibonacci numbers for JavaScript + +### :game_die: Randomness + - [@randomized/random](https://github.com/randomized-algorithm/random): Randomness algorithms for JavaScript + - [@entropy-source/pseudo-random](https://github.com/entropy-source/pseudo-random) : Pseudorandom number generators for JavaScript + +### :brain: Hard problems + - :satisfied: [@aureooms/js-sat](https://github.com/make-github-pseudonymous-again/js-sat) : Boolean formula satisfiability algorithms for Javascript + - :school_satchel: [@aureooms/js-knapsack](https://github.com/make-github-pseudonymous-again/js-knapsack) : + Knapsack problem algorithms for JavaScript + - :test_tube: [@aureooms/js-metaheuristics](https://github.com/make-github-pseudonymous-again/js-metaheuristics) : + Metaheuristic algorithms for JavaScript + +### :left_right_arrow: Sytems of equalities and inequalities + - [@aureooms/js-equation](https://github.com/make-github-pseudonymous-again/js-equation) : equations system code bricks for JavaScript + +### :broom: Combinatorics + - :exclamation: [@combinatorics/factorial](https://github.com/computational-combinatorics/factorial): Factorial function for JavaScript + - :seat: [@combinatorics/permutation](https://github.com/computational-combinatorics/permutation): Permutations library for JavaScript + - :zebra: [@combinatorics/n-permutations](https://github.com/computational-combinatorics/n-permutations): Set n-permutations for JavaScript + - :hippopotamus: [@combinatorics/n-combinations](https://github.com/computational-combinatorics/n-combinations): Set n-combinations for JavaScript + - :rhinoceros: [@combinatorics/n-multicombinations](https://github.com/computational-combinatorics/n-multicombinations): Set n-multicombinations for JavaScript + - :bento: [@combinatorics/set-partition](https://github.com/computational-combinatorics/set-partition): Set partition algorithms for Javascript + Those packages aim to provide *code bricks* that are as generic as possible. Some examples are a Gauss-Jordan method that can work with any number model, a -Karatsuba algorithm that can handle any block size, a Graham Scan algorithm +Karatsuba algorithm that can handle any input size, a Graham Scan algorithm that works with clockwise or counter clockwise ordering, and a Monotone Chain algorithm that can be used as a triangulation algorithm without any change. -## Reference +## :scroll: Reference A list of links and projects focusing on algorithm implementation. -### Projects implementing algorithms in JavaScript +### :coffee: Projects implementing algorithms in JavaScript - https://github.com/felipernb/algorithms.js - https://github.com/mgechev/javascript-algorithms - https://github.com/nzakas/computer-science-in-javascript + - https://github.com/benoitvallon/computer-science-in-javascript - http://www.nayuki.io -### Projects implementing algorithms in other languages +### :peacock: Projects implementing algorithms in other languages - https://github.com/xtaci/algorithms (C++) - https://github.com/fragglet/c-algorithms (C) @@ -81,7 +149,7 @@ A list of links and projects focusing on algorithm implementation. - http://www.nayuki.io (C, C++, Java, C#, Python, Haskell, MATLAB and others) - http://rosettacode.org (All kinds of languages) -### Others +### :link: Others - http://stackoverflow.com/questions/26301/your-favourite-algorithm-and-the-lesson-it-taught-you - http://cglab.ca/publications.html diff --git a/bower.json b/bower.json index c9d63b9..efc624a 100644 --- a/bower.json +++ b/bower.json @@ -1,5 +1,5 @@ { - "homepage": "https://aureooms.github.io/js-algorithms", + "homepage": "https://make-github-pseudonymous-again.github.io/js-algorithms", "name": "aureooms-js-algorithms", "license": "AGPL-3.0", "description": "playground for algorithmic code bricks in JavaScript", diff --git a/js/dist/algorithms.js b/js/dist/algorithms.js index 742e059..5588699 100644 --- a/js/dist/algorithms.js +++ b/js/dist/algorithms.js @@ -1162,12 +1162,12 @@ function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); } if (typeof exports === "object") { definition(exports); } else if (typeof define === "function" && define.amd) { - define("aureooms-js-algorithms", [], function () { + define("@aureooms/js-algorithms", [], function () { return definition({}); }); } else if (typeof window === "object" && typeof window.document === "object") { definition(window["algorithms"] = {}); - } else console.error("unable to detect type of module to define for aureooms-js-algorithms"); + } else console.error("unable to detect type of module to define for @aureooms/js-algorithms"); })(); // empty or one element array case diff --git a/js/dist/algorithms.min.js b/js/dist/algorithms.min.js index 5eb1d11..6e0eb80 100644 --- a/js/dist/algorithms.min.js +++ b/js/dist/algorithms.min.js @@ -1,2 +1,2 @@ -"use strict";function _toArray(r){return Array.isArray(r)?r:Array.from(r)}var _slicedToArray=function(){function r(r,e){var t=[],n=!0,a=!1,o=void 0;try{for(var i,u=r[Symbol.iterator]();!(n=(i=u.next()).done)&&(t.push(i.value),!e||t.length!==e);n=!0);}catch(f){a=!0,o=f}finally{try{!n&&u["return"]&&u["return"]()}finally{if(a)throw o}}return t}return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return r(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();!function(){var r=function(r,e){var t=function(r,e,t,n,a,o,i,u,f,c){for(var s,l,v,d,y,b;f>u;++u){l=e,s=o-1;do v=r[l],d=n[s],y=i[u],b=v+d,-y===b&&c(v,d,y),b>-y?--s:++l;while(t>l&&s>=a)}};r._3sum_n2=t;var n=function _(r,e,t,n,a,o,i,u,f,c,s,l){var v,d,y,b,x;n>a||o>i||u>f||c>s||(v=e[n],d=t[i],y=e[f],b=t[c],x=r(v,d,y,b),0===x?(l(n,i,f,c),_(r,e,t,n+1,a,o,i,u,f,c,s,l),_(r,e,t,n,n,o,i-1,u,f,c,s,l),_(r,e,t,n,n,i,i,u,f-1,c,s,l)):0>x?(_(r,e,t,n+1,a,o,i,u,f,c,s,l),_(r,e,t,n,n,o,i,u,f-1,c,s,l)):(_(r,e,t,n,a,o,i-1,u,f,c,s,l),_(r,e,t,n,a,i,i,u,f,c+1,s,l)))};r.sortxy_n3=n;var a=function m(r,e,t,n,a,o,i,u,f,c,s,l){var v,d,y,b,x;n>a||o>i||u>f||c>s||(v=e[n],d=t[o],y=e[u],b=t[c],x=r(v,d,y,b),0===x&&l(n,o,u,c),m(r,e,t,n+1,a,o,i,u,f,c,s,l),m(r,e,t,n,n,o+1,i,u,f,c,s,l),m(r,e,t,n,n,o,o,u+1,f,c,s,l),m(r,e,t,n,n,o,o,u,u,c+1,s,l))};r.sortxy_n4=a;var o=function(r,e,t){for(;e>r;++r)t(r)},i=function(r,e,t){for(;--e>=r;)t(e)};r.fiter=o,r.biter=i;var u=function(r,t,n,a,o,i){var u=regeneratorRuntime.mark(function f(u,c,s,l,v,d){var y,b,x,_,k,m,p,h,w,g;return regeneratorRuntime.wrap(function(A){for(;;)switch(A.prev=A.next){case 0:if(y=e,b=e,x=e,_=e,k=e,m=e,p=e,h=e,w=e,g=e,!(s>=l-1)){A.next=3;break}return A.abrupt("return");case 3:if(v!==d){A.next=19;break}k=o(a,c,s,l),x=k;case 6:if(!(l>x)){A.next=17;break}_=s;case 8:if(!(k>_)){A.next=14;break}return A.next=11,[c[x],c[_]];case 11:++_,A.next=8;break;case 14:++x,A.next=6;break;case 17:A.next=32;break;case 19:return y=(s+l)/2|0,r(u(v),c,s,l,y),b=c[y][v],x=o(t(v,b),c,s,y),A.delegateYield(f(u,c,s,x,v,d),"t0",24);case 24:return _=o(n(v,b),c,y+1,l),A.delegateYield(f(u,c,_,l,v,d),"t1",26);case 26:return k=o(a,c,s,x),m=o(a,c,_,l),p=x-k,h=l-m,p===h?(i(c,m,l,c,k),l=_):h>p?(i(c,k,x,c,m),w=m+p-_,g=l-(m+p),w>=g?i(c,m+p,l,c,_):i(c,l-w,l,c,_),l=_+g):(i(c,m,l,c,k),w=x-(k+h),g=_-x,w>=g?i(c,x,_,c,k+h):i(c,_-w,_,c,k+h),l=_-w),A.delegateYield(f(u,c,s,l,v+1,d),"t2",32);case 32:case"end":return A.stop()}},f,this)});return u};r.__bdpdc__=u;var f=function(r,t){var n=regeneratorRuntime.mark(function a(n,o,i,u,f,c){var s,l,v,d,y;return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(s=e,l=e,v=e,d=e,y=e,!(i>=u-1)){a.next=3;break}return a.abrupt("return");case 3:v=t(r,o,i,u),s=v;case 5:if(!(u>s)){a.next=24;break}l=i;case 7:if(!(v>l)){a.next=21;break}d=f;case 9:if(!(c>d)){a.next=16;break}if(y=n(d),!(y(o[s],o[l])<0)){a.next=13;break}return a.abrupt("continue",18);case 13:++d,a.next=9;break;case 16:return a.next=18,[o[s],o[l]];case 18:++l,a.next=7;break;case 21:++s,a.next=5;break;case 24:case"end":return a.stop()}},a,this)});return n};r.__bdpdn2__=f;var c=function(r,e,t){var n,a;for(a=1,n=1;r>n;++n)a=a*(t-n)/t;for(;e>n;++n)a=a*(t-r)/t;return 1-a};r.samebirthday=c;var s=function(r){return function(e,t){var n;return n=e-t,-r>n?-1:n>r?1:0}};r.__absepsilon__=s;var l=function(r){return function(e,t){var n;return 0===t?e:0===e?-t:(n=e/t-1,-r>n?-1:n>r?1:0)}};r.__relepsilon__=l;var v=function(r,t){var n=[],a=!0,o=!1,i=e;try{r:for(var u,f=t[Symbol.iterator]();!(a=(u=f.next()).done);a=!0){var c=u.value,s=!0,l=!1,v=e;try{for(var d,y=n[Symbol.iterator]();!(s=(d=y.next()).done);s=!0){var b=d.value;if(!r(c,b))continue r}}catch(x){l=!0,v=x}finally{try{!s&&y["return"]&&y["return"]()}finally{if(l)throw v}}n.push(c)}}catch(x){o=!0,i=x}finally{try{!a&&f["return"]&&f["return"]()}finally{if(o)throw i}}return n};r.max_independent_set=v;var d=function(r,e,t,n){var a,o,i,u,f;for(a=t,o=n-1;o>=a;){for(i=t;a>i&&!r(e[i],e[o]);++i);if(a>i)--o;else{for(f=e[o],e[o]=e[a],e[a]=f,u=a+1;o>=u;)r(e[a],e[o])?--o:r(e[o],e[a])?(f=e[o],e[o]=e[a],e[a]=f,--o):(f=e[o],e[o]=e[u],e[u]=f,++u);++a}}return a};r.clarkson=d;var y=function(r,t,n,a,o){var i=function u(i){if(o(i))return a(i);var f=t(r(i)),c=_toArray(f),s=c[0],l=c.slice(1),v=u(s),d=_slicedToArray(v,2),y=d[0],b=d[1],x=!0,_=!1,k=e;try{for(var m,p=l[Symbol.iterator]();!(x=(m=p.next()).done);x=!0){var h=m.value;if(n(h,b)){var w=u(h),g=_slicedToArray(w,2);y=g[0],b=g[1]}}}catch(A){_=!0,k=A}finally{try{!x&&p["return"]&&p["return"]()}finally{if(_)throw k}}return[y,b]};return i};r.chan=y;var b=function(r,e,t,n,a,o,i,u,f,c,s,l){var v,d,y,b,x,_;for(x=t-e,k=o-a-1,_=1+k/2,y=u;f>y;++y)i[y]=n[a];for(d=1,v=1;_>d;++d,v*=x)for(y=u,b=0;f>y;++y,b=((b+1)/v|0)%x)i[y]+=n[a+d]*r[e+b];for(v=1;d<=k;++d,v*=x)for(y=s,b=0;l>y;++y,b=((b+1)/v|0)%x)c[y]+=n[a+d]*r[e+b]};r.evenkldtto2sum=b;var x=function(r,e,t,n,a,o,i,u,f,c,s,l,v,d,y){var b,x,_,m,p,h;for(p=t-e,k=o-a-1,h=2+(k-1)/2,x=2,b=1;h>x;++x,b*=p)for(_=u,m=0;f>_;++_,m=((m+1)/b|0)%p)i[_]+=n[a+x]*r[e+m];for(b=1;x<=k;++x,b*=p)for(_=s,m=0;l>_;++_,m=((m+1)/b|0)%p)c[_]+=n[a+x]*r[e+m];for(m=0;p>m;++m)v[d+m]=n[a+1]*r[e+m]+n[a]};return r.oddkldtto3sum=x,r};"object"==typeof exports?r(exports):"function"==typeof define&&define.amd?define("aureooms-js-algorithms",[],function(){return r({})}):"object"==typeof window&&"object"==typeof window.document?r(window.algorithms={}):console.error("unable to detect type of module to define for aureooms-js-algorithms")}(); +"use strict";function _toArray(r){return Array.isArray(r)?r:Array.from(r)}var _slicedToArray=function(){function r(r,e){var t=[],n=!0,a=!1,o=void 0;try{for(var i,u=r[Symbol.iterator]();!(n=(i=u.next()).done)&&(t.push(i.value),!e||t.length!==e);n=!0);}catch(f){a=!0,o=f}finally{try{!n&&u["return"]&&u["return"]()}finally{if(a)throw o}}return t}return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return r(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();!function(){var r=function(r,e){var t=function(r,e,t,n,a,o,i,u,f,c){for(var s,l,v,d,y,b;f>u;++u){l=e,s=o-1;do v=r[l],d=n[s],y=i[u],b=v+d,-y===b&&c(v,d,y),b>-y?--s:++l;while(t>l&&s>=a)}};r._3sum_n2=t;var n=function _(r,e,t,n,a,o,i,u,f,c,s,l){var v,d,y,b,x;n>a||o>i||u>f||c>s||(v=e[n],d=t[i],y=e[f],b=t[c],x=r(v,d,y,b),0===x?(l(n,i,f,c),_(r,e,t,n+1,a,o,i,u,f,c,s,l),_(r,e,t,n,n,o,i-1,u,f,c,s,l),_(r,e,t,n,n,i,i,u,f-1,c,s,l)):0>x?(_(r,e,t,n+1,a,o,i,u,f,c,s,l),_(r,e,t,n,n,o,i,u,f-1,c,s,l)):(_(r,e,t,n,a,o,i-1,u,f,c,s,l),_(r,e,t,n,a,i,i,u,f,c+1,s,l)))};r.sortxy_n3=n;var a=function m(r,e,t,n,a,o,i,u,f,c,s,l){var v,d,y,b,x;n>a||o>i||u>f||c>s||(v=e[n],d=t[o],y=e[u],b=t[c],x=r(v,d,y,b),0===x&&l(n,o,u,c),m(r,e,t,n+1,a,o,i,u,f,c,s,l),m(r,e,t,n,n,o+1,i,u,f,c,s,l),m(r,e,t,n,n,o,o,u+1,f,c,s,l),m(r,e,t,n,n,o,o,u,u,c+1,s,l))};r.sortxy_n4=a;var o=function(r,e,t){for(;e>r;++r)t(r)},i=function(r,e,t){for(;--e>=r;)t(e)};r.fiter=o,r.biter=i;var u=function(r,t,n,a,o,i){var u=regeneratorRuntime.mark(function f(u,c,s,l,v,d){var y,b,x,_,k,m,p,h,w,g;return regeneratorRuntime.wrap(function(A){for(;;)switch(A.prev=A.next){case 0:if(y=e,b=e,x=e,_=e,k=e,m=e,p=e,h=e,w=e,g=e,!(s>=l-1)){A.next=3;break}return A.abrupt("return");case 3:if(v!==d){A.next=19;break}k=o(a,c,s,l),x=k;case 6:if(!(l>x)){A.next=17;break}_=s;case 8:if(!(k>_)){A.next=14;break}return A.next=11,[c[x],c[_]];case 11:++_,A.next=8;break;case 14:++x,A.next=6;break;case 17:A.next=32;break;case 19:return y=(s+l)/2|0,r(u(v),c,s,l,y),b=c[y][v],x=o(t(v,b),c,s,y),A.delegateYield(f(u,c,s,x,v,d),"t0",24);case 24:return _=o(n(v,b),c,y+1,l),A.delegateYield(f(u,c,_,l,v,d),"t1",26);case 26:return k=o(a,c,s,x),m=o(a,c,_,l),p=x-k,h=l-m,p===h?(i(c,m,l,c,k),l=_):h>p?(i(c,k,x,c,m),w=m+p-_,g=l-(m+p),w>=g?i(c,m+p,l,c,_):i(c,l-w,l,c,_),l=_+g):(i(c,m,l,c,k),w=x-(k+h),g=_-x,w>=g?i(c,x,_,c,k+h):i(c,_-w,_,c,k+h),l=_-w),A.delegateYield(f(u,c,s,l,v+1,d),"t2",32);case 32:case"end":return A.stop()}},f,this)});return u};r.__bdpdc__=u;var f=function(r,t){var n=regeneratorRuntime.mark(function a(n,o,i,u,f,c){var s,l,v,d,y;return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(s=e,l=e,v=e,d=e,y=e,!(i>=u-1)){a.next=3;break}return a.abrupt("return");case 3:v=t(r,o,i,u),s=v;case 5:if(!(u>s)){a.next=24;break}l=i;case 7:if(!(v>l)){a.next=21;break}d=f;case 9:if(!(c>d)){a.next=16;break}if(y=n(d),!(y(o[s],o[l])<0)){a.next=13;break}return a.abrupt("continue",18);case 13:++d,a.next=9;break;case 16:return a.next=18,[o[s],o[l]];case 18:++l,a.next=7;break;case 21:++s,a.next=5;break;case 24:case"end":return a.stop()}},a,this)});return n};r.__bdpdn2__=f;var c=function(r,e,t){var n,a;for(a=1,n=1;r>n;++n)a=a*(t-n)/t;for(;e>n;++n)a=a*(t-r)/t;return 1-a};r.samebirthday=c;var s=function(r){return function(e,t){var n;return n=e-t,-r>n?-1:n>r?1:0}};r.__absepsilon__=s;var l=function(r){return function(e,t){var n;return 0===t?e:0===e?-t:(n=e/t-1,-r>n?-1:n>r?1:0)}};r.__relepsilon__=l;var v=function(r,t){var n=[],a=!0,o=!1,i=e;try{r:for(var u,f=t[Symbol.iterator]();!(a=(u=f.next()).done);a=!0){var c=u.value,s=!0,l=!1,v=e;try{for(var d,y=n[Symbol.iterator]();!(s=(d=y.next()).done);s=!0){var b=d.value;if(!r(c,b))continue r}}catch(x){l=!0,v=x}finally{try{!s&&y["return"]&&y["return"]()}finally{if(l)throw v}}n.push(c)}}catch(x){o=!0,i=x}finally{try{!a&&f["return"]&&f["return"]()}finally{if(o)throw i}}return n};r.max_independent_set=v;var d=function(r,e,t,n){var a,o,i,u,f;for(a=t,o=n-1;o>=a;){for(i=t;a>i&&!r(e[i],e[o]);++i);if(a>i)--o;else{for(f=e[o],e[o]=e[a],e[a]=f,u=a+1;o>=u;)r(e[a],e[o])?--o:r(e[o],e[a])?(f=e[o],e[o]=e[a],e[a]=f,--o):(f=e[o],e[o]=e[u],e[u]=f,++u);++a}}return a};r.clarkson=d;var y=function(r,t,n,a,o){var i=function u(i){if(o(i))return a(i);var f=t(r(i)),c=_toArray(f),s=c[0],l=c.slice(1),v=u(s),d=_slicedToArray(v,2),y=d[0],b=d[1],x=!0,_=!1,k=e;try{for(var m,p=l[Symbol.iterator]();!(x=(m=p.next()).done);x=!0){var h=m.value;if(n(h,b)){var w=u(h),g=_slicedToArray(w,2);y=g[0],b=g[1]}}}catch(A){_=!0,k=A}finally{try{!x&&p["return"]&&p["return"]()}finally{if(_)throw k}}return[y,b]};return i};r.chan=y;var b=function(r,e,t,n,a,o,i,u,f,c,s,l){var v,d,y,b,x,_;for(x=t-e,k=o-a-1,_=1+k/2,y=u;f>y;++y)i[y]=n[a];for(d=1,v=1;_>d;++d,v*=x)for(y=u,b=0;f>y;++y,b=((b+1)/v|0)%x)i[y]+=n[a+d]*r[e+b];for(v=1;d<=k;++d,v*=x)for(y=s,b=0;l>y;++y,b=((b+1)/v|0)%x)c[y]+=n[a+d]*r[e+b]};r.evenkldtto2sum=b;var x=function(r,e,t,n,a,o,i,u,f,c,s,l,v,d,y){var b,x,_,m,p,h;for(p=t-e,k=o-a-1,h=2+(k-1)/2,x=2,b=1;h>x;++x,b*=p)for(_=u,m=0;f>_;++_,m=((m+1)/b|0)%p)i[_]+=n[a+x]*r[e+m];for(b=1;x<=k;++x,b*=p)for(_=s,m=0;l>_;++_,m=((m+1)/b|0)%p)c[_]+=n[a+x]*r[e+m];for(m=0;p>m;++m)v[d+m]=n[a+1]*r[e+m]+n[a]};return r.oddkldtto3sum=x,r};"object"==typeof exports?r(exports):"function"==typeof define&&define.amd?define("@aureooms/js-algorithms",[],function(){return r({})}):"object"==typeof window&&"object"==typeof window.document?r(window.algorithms={}):console.error("unable to detect type of module to define for @aureooms/js-algorithms")}(); //# sourceMappingURL=js/dist/algorithms.js.map \ No newline at end of file diff --git a/js/src/epsilon/absepsilon.js b/js/src/epsilon/absepsilon.js deleted file mode 100644 index e57fc03..0000000 --- a/js/src/epsilon/absepsilon.js +++ /dev/null @@ -1,18 +0,0 @@ - - -var __absepsilon__ = function ( epsilon ) { - - - return function ( a, b ) { - - var r; - - r = a - b; - - return r < -epsilon ? -1 : r > epsilon ? 1 : 0; - - }; - -}; - -exports.__absepsilon__ = __absepsilon__; diff --git a/js/src/epsilon/relepsilon.js b/js/src/epsilon/relepsilon.js deleted file mode 100644 index b8cbad3..0000000 --- a/js/src/epsilon/relepsilon.js +++ /dev/null @@ -1,29 +0,0 @@ - -var __relepsilon__ = function ( epsilon ) { - - - return function ( a, b ) { - - var r; - - if ( b === 0 ) { - return a; - } - - else if ( a === 0 ) { - return -b; - } - - else { - - r = a / b - 1; - - return r < -epsilon ? -1 : r > epsilon ? 1 : 0; - - } - - }; - -}; - -exports.__relepsilon__ = __relepsilon__; diff --git a/js/src/minima/clarkson.js b/js/src/minima/clarkson.js deleted file mode 100644 index 82b93a9..0000000 --- a/js/src/minima/clarkson.js +++ /dev/null @@ -1,119 +0,0 @@ - -/** - * Output sensitive inplace algorithm to find the minima set of a set S of - * elements according to some partial order. - * - * Uses at most 3nA comparisons where A is the cardinality of the minima set. - * - * For (1), at most nA comparisons are used since we compare each element of S - * with each elements of the minima set which is of cardinality at most A - * during the execution of the algorithm. - * - * For (2), for each executed loop we - * obtain a new minimum and increase the size of the constructed minima set by - * 1, hence there are at most A loops execution, each of which loops over at - * most n elements. (2) uses thus at most nA comparisons. - * - * The running time is dominated by the comparison time and thus the complexity - * of this algorihtm is O(nA). - * - * Description and context in - * ------------------------------------------ - * More Output-Sensitive Geometric Algorithms. - * -------------------- Kenneth L. Clarkson - - */ - -var clarkson = function ( prec , a , i , j ) { - - // - // This algorithms reorganizes the input array `a` as follows - // - elements that are minima are put at the front of `a` - // - other elements are put at the back of `a` - // - // During the algorithm, `a` looks like this - // - // ------------------------------------------------------ - // | minima set | candidate elements | discarded elements | - // ------------------------------------------------------ - // i min dis j - - var min , dis , k , inc , tmp ; - - min = i ; - dis = j - 1 ; - - // While there are candidate elements left. - - while ( min <= dis ) { - - // (1) Determine if the right-most candidate should be discarded because it - // is dominated by one of the minima elements of the minima set in - // construction. - - for ( k = i ; k < min && !prec( a[k] , a[dis] ) ; ++k ) ; - - // If so, discard it. - - if ( k < min ) --dis ; - - // (2) Otherwise, scan the candidates for a minimum. If at this point the - // candidate set is not empty, at least one of its elements must be a - // minimum. We scan the candidate list to find such a minimum. - - else { - - // Store the current minimum as the left-most candidate. - - tmp = a[dis] ; - a[dis] = a[min] ; - a[min] = tmp ; - - // For each other candidate, right-to-left. - - for ( inc = min + 1 ; inc <= dis ; ) { - - // If the current minimum precedes the right-most candidate, - // discard the right-most candidate. - - if ( prec( a[min] , a[dis] ) ) --dis ; - - // Else, if the right-most candidate precedes the current - // minimum, we can discard the current minimum and the - // right-most candidate becomes the current minimum. - - else if ( prec( a[dis] , a[min] ) ) { - tmp = a[dis] ; - a[dis] = a[min] ; - a[min] = tmp ; - --dis ; - } - - // Otherwise, we save the candidate for the next round. - - else { - tmp = a[dis] ; - a[dis] = a[inc] ; - a[inc] = tmp ; - ++inc ; - } - - } - - // The above loop selects a new minimum from the set of candidates - // and places it at position `min`. We now increase the `min` - // counter to move this minimum from the candidate list to the - // minima set. - - ++min ; - - } - - } - - // The algorithm returns the outer right bound of the minima set a[i:min]. - - return min ; - -} ; - -exports.clarkson = clarkson ; diff --git a/package.json b/package.json index 2fdf4b0..8cba910 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { - "name": "aureooms-js-algorithms", - "description": "playground for algorithmic code bricks in JavaScript", - "homepage": "https://aureooms.github.io/js-algorithms", + "name": "@aureooms/js-algorithms", + "description": "Playground for algorithms in JavaScript", + "homepage": "https://make-github-pseudonymous-again.github.io/js-algorithms", "main": "js/dist/algorithms.js", "version": "3.0.7", "repository": { - "url": "https://github.com/aureooms/js-algorithms.git", + "url": "https://github.com/make-github-pseudonymous-again/js-algorithms.git", "type": "git" }, "keywords": [ @@ -24,24 +24,24 @@ }, "author": "aureooms", "devDependencies": { - "aureooms-js-array": "^3.1.0", - "aureooms-js-compare": "^1.4.3", - "aureooms-js-functools": "^2.0.3", - "aureooms-js-itertools": "^1.3.0", - "aureooms-js-operator": "^1.0.2", - "aureooms-js-partition": "^7.0.0", - "aureooms-js-random": "^1.0.1", - "aureooms-js-selection": "^8.0.1", - "aureooms-js-sort": "^6.0.0", - "aureooms-js-splitting": "^4.0.2", + "@aureooms/js-array": "^4.0.0", + "@aureooms/js-compare": "^1.4.3", + "@aureooms/js-functools": "^2.0.3", + "@aureooms/js-itertools": "^3.0.0", + "@aureooms/js-operator": "^1.0.2", + "@aureooms/js-partition": "^8.0.0", + "@aureooms/js-random": "^2.0.0", + "@aureooms/js-selection": "^9.0.0", + "@aureooms/js-sort": "^7.0.0", + "@aureooms/js-splitting": "^4.0.2", "aureooms-node-package": "^6.0.1" }, "bugs": { - "url": "https://github.com/aureooms/js-algorithms/issues" + "url": "https://github.com/make-github-pseudonymous-again/js-algorithms/issues" }, "dependencies": {}, "license": "AGPL-3.0", "spm": { "main": "js/dist/algorithms.js" } -} \ No newline at end of file +} diff --git a/test/js/src/3sum.js b/test/js/src/3sum.js index fa41eec..a36f2db 100644 --- a/test/js/src/3sum.js +++ b/test/js/src/3sum.js @@ -1,6 +1,6 @@ var util = require( "util" ); -var array = require( "aureooms-js-array" ); +var array = require( "@aureooms/js-array" ); test("3sum", function(){ diff --git a/test/js/src/bdp.js b/test/js/src/bdp.js index 95b4e41..85092bf 100644 --- a/test/js/src/bdp.js +++ b/test/js/src/bdp.js @@ -2,15 +2,15 @@ var n; -var itertools = require( "aureooms-js-itertools" ); -var functools = require( "aureooms-js-functools" ); -var splitting = require( "aureooms-js-splitting" ); -var partition = require( "aureooms-js-partition" ) ; -var selection = require( "aureooms-js-selection" ) ; -var operator = require( "aureooms-js-operator" ); -var compare = require( "aureooms-js-compare" ); -var random = require( "aureooms-js-random" ); -var array = require( "aureooms-js-array" ); +var itertools = require( "@aureooms/js-itertools" ); +var functools = require( "@aureooms/js-functools" ); +var splitting = require( "@aureooms/js-splitting" ); +var partition = require( "@aureooms/js-partition" ) ; +var selection = require( "@aureooms/js-selection" ) ; +var operator = require( "@aureooms/js-operator" ); +var compare = require( "@aureooms/js-compare" ); +var random = require( "@aureooms/js-random" ); +var array = require( "@aureooms/js-array" ); var one = function ( bdp, __f__, a, i, j, di, dj, expected ) { diff --git a/test/js/src/epsilon.js b/test/js/src/epsilon.js deleted file mode 100644 index 41fd692..0000000 --- a/test/js/src/epsilon.js +++ /dev/null @@ -1,62 +0,0 @@ - - -test ( "epsilon", function ( ) { - - var absepsilon, relepsilon, epsilon; - - epsilon = Math.pow( 2, -10 ); - morethanepsilon = epsilon + epsilon / 128; - - absepsilon = algorithms.__absepsilon__( epsilon ); - relepsilon = algorithms.__relepsilon__( epsilon ); - - - ok( absepsilon( 0, 0 ) === 0, " absolute 0 === 0 " ); - ok( relepsilon( 0, 0 ) === 0, " relative 0 === 0 " ); - - - ok( absepsilon( epsilon, 0 ) === 0, " absolute e === 0 " ); - ok( absepsilon( -epsilon, 0 ) === 0, " absolute -e === 0 " ); - ok( absepsilon( 0, epsilon ) === 0, " absolute 0 === e " ); - ok( absepsilon( 0, -epsilon ) === 0, " absolute 0 === -e " ); - - ok( relepsilon( epsilon, 0 ) > 0, " relative e > 0 " ); - ok( relepsilon( -epsilon, 0 ) < 0, " relative -e < 0 " ); - ok( relepsilon( 0, epsilon ) < 0, " relative 0 < e " ); - ok( relepsilon( 0, -epsilon ) > 0, " relative 0 > -e " ); - - - ok( absepsilon( morethanepsilon, 0 ) > 0, " absolute e' > 0 " ); - ok( absepsilon( -morethanepsilon, 0 ) < 0, " absolute -e' < 0 " ); - ok( absepsilon( 0, morethanepsilon ) < 0, " absolute 0 < e' " ); - ok( absepsilon( 0, -morethanepsilon ) > 0, " absolute 0 < -e' " ); - - ok( relepsilon( morethanepsilon, 0 ) > 0, " relative e' > 0 " ); - ok( relepsilon( -morethanepsilon, 0 ) < 0, " relative -e' < 0 " ); - ok( relepsilon( 0, morethanepsilon ) < 0, " relative 0 < e' " ); - ok( relepsilon( 0, -morethanepsilon ) > 0, " relative 0 > -e' " ); - - - ok( absepsilon( 1 + epsilon, 1 ) === 0, " absolute 1 + e === 1 " ); - ok( absepsilon( 1 - epsilon, 1 ) === 0, " absolute 1 - e === 1 " ); - ok( absepsilon( 1, 1 + epsilon ) === 0, " absolute 1 === 1 + e " ); - ok( absepsilon( 1, 1 - epsilon ) === 0, " absolute 1 === 1 - e " ); - - ok( relepsilon( 1 * ( 1 + epsilon ), 1 ) === 0, " relative 1 * ( 1 + e ) === 1 " ); - ok( relepsilon( 1 / ( 1 + epsilon ), 1 ) === 0, " relative 1 / ( 1 + e ) === 1 " ); - ok( relepsilon( 1, 1 * ( 1 + epsilon ) ) === 0, " relative 1 === 1 * ( 1 + e ) " ); - ok( relepsilon( 1, 1 / ( 1 + epsilon ) ) === 0, " relative 1 === 1 / ( 1 + e ) " ); - - ok( absepsilon( 1 + morethanepsilon, 1 ) > 0, " absolute 1 + e' > 1 " ); - ok( absepsilon( 1 - morethanepsilon, 1 ) < 0, " absolute 1 - e' < 1 " ); - ok( absepsilon( 1, 1 + morethanepsilon ) < 0, " absolute 1 < 1 + e' " ); - ok( absepsilon( 1, 1 - morethanepsilon ) > 0, " absolute 1 > 1 - e' " ); - - ok( relepsilon( 1 * ( 1 + morethanepsilon ), 1 ) > 0, " relative 1 * ( 1 + e' ) > 1 " ); - ok( relepsilon( 1 / ( 1 + morethanepsilon ), 1 ) < 0, " relative 1 / ( 1 + e' ) < 1 " ); - ok( relepsilon( 1, 1 * ( 1 + morethanepsilon ) ) < 0, " relative 1 < 1 * ( 1 + e' ) " ); - ok( relepsilon( 1, 1 / ( 1 + morethanepsilon ) ) > 0, " relative 1 > 1 / ( 1 + e' ) " ); - - - -} ); diff --git a/test/js/src/iter.js b/test/js/src/iter.js index 22fd9c0..86113bd 100644 --- a/test/js/src/iter.js +++ b/test/js/src/iter.js @@ -1,5 +1,5 @@ -var array = require( "aureooms-js-array" ); +var array = require( "@aureooms/js-array" ); test( "iter", function () { diff --git a/test/js/src/ksum/sortxy.js b/test/js/src/ksum/sortxy.js index 5a4e91b..a099062 100644 --- a/test/js/src/ksum/sortxy.js +++ b/test/js/src/ksum/sortxy.js @@ -1,6 +1,6 @@ var util = require( "util" ) ; -var array = require( "aureooms-js-array" ) ; +var array = require( "@aureooms/js-array" ) ; test( "sortxy" , function ( ) { diff --git a/test/js/src/minima.js b/test/js/src/minima.js deleted file mode 100644 index 671f8f1..0000000 --- a/test/js/src/minima.js +++ /dev/null @@ -1,63 +0,0 @@ - -var sort = require( "aureooms-js-sort" ) ; -var array = require( "aureooms-js-array" ) ; -var random = require( "aureooms-js-random" ) ; -var compare = require( "aureooms-js-compare" ) ; - -test( "minima 1" , function ( ) { - - var a = [ 1 , 2 , 3 , 4 , 6 , 12 ] ; - - var divides = function ( a , b ) { return b % a === 0 ; } ; - - random.shuffle( a , 0 , a.length ) ; - - var min = algorithms.clarkson( divides , a , 0 , a.length ) ; - - deepEqual( min , 1 , "minima set has cardinality 1" ) ; - - deepEqual( a[0] , 1 , "minimum is 1" ) ; - -} ) ; - -test( "minima 2,3" , function ( ) { - - var a = [ 1 , 2 , 3 , 4 , 6 , 12 ] ; - - var i = 1 ; - - var j = a.length ; - - var divides = function ( a , b ) { return b % a === 0 ; } ; - - random.shuffle( a , i , j ) ; - - var min = algorithms.clarkson( divides , a , i , j ) ; - - deepEqual( min - i , 2 , "minima set has cardinality 2" ) ; - - sort.insertionsort( compare.increasing , a , i , min ) ; - - deepEqual( a[i+0] , 2 , "1st minimum is 2" ) ; - deepEqual( a[i+1] , 3 , "2nd minimum is 3" ) ; - -} ) ; - - -test( "minima totally unordered set" , function ( ) { - - n = 1000 ; - - var a = array.alloc( n ) ; - - array.iota( a , 0 , n , 0 ) ; - - var prec = function ( a , b ) { return false ; } ; - - random.shuffle( a , 0 , n ) ; - - var min = algorithms.clarkson( prec , a , 0 , n ) ; - - deepEqual( min , n , "minima set has cardinality n" ) ; - -} ) ;