@combinatorics/set-partition
Version:
Set partition algorithms for JavaScript
3 lines (2 loc) • 2.95 kB
JavaScript
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@iterable-iterator/select"),require("@iterable-iterator/list"),require("@iterable-iterator/map")):"function"==typeof define&&define.amd?define(["exports","@iterable-iterator/select","@iterable-iterator/list","@iterable-iterator/map"],r):r((e||self).setPartition={},e.select,e.list,e.map)}(this,function(e,r,t,n){var a=regeneratorRuntime.mark(o);function o(e){var r,t,n,o,i;return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,e;case 2:r=[e];case 3:return n=r[(t=r.length)-1],a.next=8,n;case 8:for(o=0;o<t;++o)i=n+r[o],r[o]=n,n=i;r.push(n),a.next=3;break;case 12:case"end":return a.stop()}},a)}var i=function(e,t){return r.nth(o(e),t)};function u(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function c(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return u(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?u(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s=regeneratorRuntime.mark(f);function f(e,r){return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(void 0===r&&(r=e.length),0!==r){a.next=6;break}return a.next=4,[];case 4:a.next=7;break;case 6:return a.delegateYield(regeneratorRuntime.mark(function a(){var o,i,u,s,l,d,p;return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:o=e[r-1],i=c(f(e,r-1));case 2:if((u=i()).done){a.next=14;break}return s=u.value,a.next=6,s.concat([[o]]);case 6:l=regeneratorRuntime.mark(function e(){var r;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=p.value,e.next=3,t.list(n.map(function(e){return e===r?e.concat([o]):e},s));case 3:case"end":return e.stop()}},e)}),d=c(s);case 8:if((p=d()).done){a.next=12;break}return a.delegateYield(l(),"t0",10);case 10:a.next=8;break;case 12:a.next=2;break;case 14:case"end":return a.stop()}},a)})(),"t0",7);case 7:case"end":return a.stop()}},s)}e._count=i,e._enumerate=f,e._sequence=o,e.count=function(e){return i(1n,e)},e.enumerate=function(e){return f(t.list(e))},e.isPartition=function(e,r){for(var t,n=new Set(e),a=c(r);!(t=a()).done;){for(var o,i=!0,u=c(t.value);!(o=u()).done;){var s=o.value;if(i=!1,!n.has(s))return!1;n.delete(s)}if(i)return!1}return 0===n.size},e.sequence=function(){return o(1n)}});
//# sourceMappingURL=index.umd.js.map